$(document).ready(function() {
	$('.menu > LI').mouseover(function() {
		var position = $(this).position();
		if ($(this).attr('class') != 'separator') {
			$(this).addClass('act');
		}
		$('#'+$('A',$(this)).attr('rel')).css({display: 'block', left: position.left+'px',top: position.top+33+'px'});

	});

	$('.menu > LI').mouseout(function() {
		var position = $(this).position();
		if (!$(this).hasClass('perm'))
			$(this).removeClass('act');
		$('#'+$('A',$(this)).attr('rel')).css({display: 'none'});
	});

	$('.header .menu-side').mouseout(function() {
		$(this).css({display: 'none'});
		$($('[rel='+$(this).attr('id')+']').parent().get(0)).removeClass('act');
	});

	$('.header .menu-side').mouseover(function() {
		$(this).css({display: 'block'});
		$($('[rel='+$(this).attr('id')+']').parent().get(0)).addClass('act');
	});

	$('.header .menu-side').mouseover(function() {
		$(this).css({display: 'block'});
		$($('[rel='+$(this).attr('id')+']').parent().get(0)).addClass('act');
	});

	$('#video-link').focus(function() {
		this.select();
	});

	$('#colors').click(function() {
		var pos = $(this).position();
		$('#colorList').css({display: 'block', left: (pos.left-5)+'px', top: (pos.top-8)+'px'})
		return false;
	});

	$('#colorList A').click(function() {
		var theme = $(this).attr('rel');
		if (theme) {
			$('link').each(function() {
				var href= $(this).attr('href');
				if (href.match('/themes/')) {
					var txt= new RegExp('themes/[^/]*/','i');
					href = href.replace(txt, 'themes/'+theme+'/');
				}
				$(this).attr('href',href);
			});
			deleteCookie(theme);
			setCookie('theme',theme,7,'/','','');
		}
		return false;

	});

	$('#colorList').mouseover(function() {
		$(this).css('display','block');
	});

	$('#colorList').mouseout(function() {
		$(this).css('display','none');
	});

});

function _request(url, container, data) {
	if (data == '') {
		jQuery.get(url,'',function(data) { $(container).html(data); }, 'html');
	}else {
		jQuery.post(url, $(data).serialize, function (data) {$(container).html(data);} , 'html');
	}
}

function advOpen(openUrl, openWidth, openHeight, openSwitch) {
	var srw = screen ? (screen.width-50)    : 750;
    var srh = screen ? (screen.height-36)   : 564;
    var openScroll  	= "0";
	var documentWrite	= "";
	var	openParameters	= "";
    if ((openWidth>srw) || (openHeight>srh)) {
        openScroll  = "1";
        if (openHeight>srh) { openWidth  = openWidth+16; openHeight = srh-50; }
        if (openWidth>srw)  { openHeight = openHeight+16; openWidth = srw-50; }
    }

    srw     = (srw - openWidth)/2;
    srh     = (srh - openHeight)/5;

  	var UTCstring;
  	Today = new Date();
  	UTCstring = Today.getUTCHours()+Today.getUTCMinutes()+Today.getUTCSeconds()+Today.getTime();

	var openName;
	openName        = "openPopup"+UTCstring;

    openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars="+openScroll+",titlebar=1,resizable=0";
    switch(openSwitch) {
        case "print":   openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0,menubar=1"; break;
        case "scroll":  openParameters  = "left="+srw+",top="+srh+",outerHeight=0,innerWidth,width="+openWidth+",innerHeight,height="+openHeight+",scrollbars=1,titlebar=1,resizable=0"; break;
    }
    var openPopup   = open(openUrl, openName, openParameters);
	if (openSwitch != 'noescape') {
		return false;
	}
}

function rotateBanersTop(pos) {
	pos = pos ? pos : 0;

	if (!bannersTop.length) {

		$('div.header').css({backgroundPosition: 'center bottom', height: '118px' });
		$('div.content').css({paddingTop: '118px'});

		return false;
	}

	if (pos > bannersTop.length - 1) {
		pos = 0;
	}

	if (bannersTop[pos][0].charAt(0) != '/') {
		$('.banner').html(bannersTop[pos][0]);
	} else {
		var flashvars = {};
		var params = {};
		var attributes = {};
		$('.banner').html('<div id="flashHolder"></div>');
		if (bannersLeft[pos][3]) {
			flashvars = {"clickTAG":bannersLeft[pos][3]}
		}
		var width = bannersTop[pos][1] > 0? bannersTop[pos][1] : 200;
		var height = bannersTop[pos][2] > 0 ? bannersTop[pos][2] : 200;
		swfobject.embedSWF(bannersTop[pos][0], "flashHolder", bannersTop[pos][1], bannersTop[pos][2], "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	}

	pos++;
	setTimeout('rotateBanersTop('+pos+')',5000);
}

function rotateBanersLeft(pos) {
	pos = pos ? pos : 0;

	if (pos > (bannersLeft.length - 1)) {
		pos = 0;
	}

	//alert(bannersLeft[pos].charAt(0));
	if (bannersLeft[pos][0].charAt(0) != '/') {
		$('.banner-left').html(bannersLeft[pos][0]);
	} else {
		var flashvars = {};
		var params = {"wmode":"transparent","bgcolor":"#ffffff"};
		var attributes = {"mode":"transparent","bgcolor":"#ffffff"};
		$('.banner-left').html('<div id="flashHolder"></div>');
		if (bannersLeft[pos][3]) {
			flashvars = {"clickTAG":bannersLeft[pos][3]}
		}
		var width = bannersLeft[pos][1] > 0 ? bannersLeft[pos][1] : 200;
		var height = bannersLeft[pos][2] > 0? bannersLeft[pos][2] : 200;
		swfobject.embedSWF(bannersLeft[pos][0], "flashHolder", width, height, "9.0.0", "expressInstall.swf", flashvars, params, attributes);
	}

	pos++;
	setTimeout('rotateBanersLeft('+pos+')',5000);

}


function setCookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}


function deleteCookie( name, path, domain ) {
	if ( Get_Cookie( name ) )
	document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function Get_Cookie( name ) {

	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function wipeThread(element, $cat) {
	$parent	= $(element.parentNode);
	$type	= $parent.attr("id") ? $parent.attr("id").split("-")[0] :  false;
	$id		= $parent.attr("id") ? $parent.attr("id").split("-")[1] :  false;

	if ($id && confirm("Sure?")) {
		var $params	= [];
		$params.push("action=del");
		$params.push("category="+$cat);
		$params.push($type+"="+$id);
		$params		= "?"+$params.join("&");

		jQuery.get(
			'/in_site/tools/ajax/messages.php'+$params, null,
			function(data){
				switch ($type) {
					case "post": $('#posts').html(data); break;
					case "thread": $('#threads').html(data); break;
				}
			}, 'html'
		);
	}
	return false;
}

function wipeComment(element) {
	$parent	= $(element.parentNode);
	$id		= $parent.attr("id") ? $parent.attr("id").split("-")[1] :  false;

	if ($id && confirm("Sure?")) {
		jQuery.get('/in_site/tools/ajax/comments.php', { "action": 'del', "id": $id },
		function(data){
			$('#commentList').html(data);
		}, 'html');
	}
	return false;
}

var $urlCall	= '/in_site/tools/ajax/call.php';
function module($mId, $eId, $sUrl) {
	$sUrl	= $urlCall + ($sUrl ? $sUrl : '');
	$.get($sUrl, {
		url: document.location.href,
		mid: $mId
	}, function($data) {
		$($eId).replaceWith($data);
	});
	return false;
}
