$(document).ready(function() {
	$('#ribbon a').css('cursor', 'pointer').click(function() {
		var id = '#' + this.id.replace(/show-/, 'description-');
	
		if ($(this).css('cursor') != 'default')	{
			$('#ribbon a').css('cursor', 'pointer');
			$(this).css('cursor', 'default');

			$('#description p').hide();
			$(id).fadeIn('normal');
		}
		
		if (hTimer)	{
			clearTimeout(hTimer);
			hTimer = null;
		}
		
		var imgId = '#' + this.id.replace(/show-/, 'cycle-');
		$('#cycle img:visible').not(imgId).css('z-index', 2).fadeOut();
		$(imgId).css('z-index', 3).fadeIn('normal');
		hTimer = setTimeout(goTimer, timer);

		return false;
	});
	
	var timer = 5000;
	var hTimer = null;
	$(window).load(function() {hTimer = setTimeout(goTimer, timer);});
	
	function goTimer() {
		var ob = $('#cycle img:visible').next();
		if (!ob.length)	{
			ob = $('#cycle img').eq(0);
		}
		
		$('#cycle img:visible').not(ob).css('z-index', 2).fadeOut();
		$(ob).css('z-index', 3).fadeIn('normal');
		
		hTimer = setTimeout(goTimer, timer);
	}
	
	
	var s1 = new SWFObject("/promo/flash/trailer.swf", "flashplayer", "406", "215", "9", "transparent");
	s1.addParam("allowfullscreen", "true");
	s1.addParam("allowscriptaccess", "always");
	s1.addParam("wmode","transparent");
	s1.addParam("flashvars","file=http://download2.pwonline.ru/clientpw/trailer_new.flv&image=/promo/images/trailer.jpg&controlbar=over");
	s1.write("flash-trailer");
	
	$(window).resize(backgroundFix).resize();
	
	function backgroundFix() {
		var backgroundHeight = 248;
		var minHeight = 860;
		var h = windowHeight() - $('#width-fix').height();
		if (h < minHeight)	h = minHeight;
		$('body').css('background-position', '50% ' + (h - backgroundHeight) + 'px');
		$('#container').height(h);
	}
	
	function windowHeight() {
		var height;
		if (window.innerHeight) {
			height = window.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight) {
			height = document.documentElement.clientHeight;
		}
		else if (document.body) {
			height = document.body.clientHeight;
		}
	
		return height;
	}
	
	var href = window.location.href;
	if (href.indexOf('site_id') != -1) {
		var vars = href.split('?')[1].split('&');
		for (var i = 0; i < vars.length; i++) {
			var v = vars[i].split('=');
			if (v[0] == 'site_id') {
				setCookie('__partner_id', v[1], getExpDate(365, 0, 0));
			}
		}
	}
});

function setCookie(name, value, expires, path, domain, secure) {
	document.cookie = name + "=" + escape(value) +
		((expires) ? "; expires=" + expires : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

function getExpDate(days, hours, minutes) {
	var expDate = new Date();
	
	if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
		expDate.setDate(expDate.getDate() + parseInt(days));
		expDate.setHours(expDate.getHours() + parseInt(hours));
		expDate.setMinutes(expDate.getMinutes() + parseInt(minutes));
		
		return expDate.toGMTString();
    }
	
	return null;
}
