$(document).ready(function(){
	/* BOF Main menu */
	$('#menu')
	.mouseover(function(e){
		var left = $(this).offset().left;
		var cloud_x = e.pageX - left + 357;
		$('#cloud').stop().animate({top:'10px', left:cloud_x+'px'},500);
	})
	.mouseout(function(e){
		$('#cloud').stop().animate({top:'10px', left:'357px'},500);
	})
	/* EOF Main menu */
	if ($(".slides").length > 0){
	    $('.slides').cycle({
			fx: 'scrollHorz',
	    	timeout: 0, 
	    	speed:  500,
			pause: 1,
			prev: '#prev2',
			next: '#next2, #more',
			before: onBefore,
			after: onAfter,
			cleartype:  1,
			sync: 0,
			fit: 1
		});
	}	
	
	$("#pause").click(
		function() {
			$('.slides').cycle("pause");
		}
	);

	$("#resume").click(
			function() {
				$('.slides').cycle("resume");
			}
	);
	
	$('#btn_fb_hlp, #logform #win_fb_hlp span#btn_close').click(function(){
		$('#win_fb_hlp').toggle('fast');
	});

	$('#foot_mobile_link, #qr_code span#btn_qr_close').click(function(){
		$('#qr_code').toggle('fast');
	});
	
	$('#btn_facebook_like').click(
		function () {
			u=location.href;
			t=document.title;
			window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');
			return false;
		}
	)
	
	// Check if #news element exists and init news ticker
	if ($("#slide-news").length > 0){
		$('#slide-news').cycle({fx: 'scrollDown', timeout:  10000});
	} // end ticker
	
	// Check for referral registration page
	if ($("#a_more_info").length > 0){
		$("#a_more_info").colorbox({
			inline:true,
			width:"650px",
    		height:"580px",
    		close:"Затвори",
			href:"#div_more_info"
		});		
		
	}
});

function onBefore (currSlideElement, nextSlideElement, options, forwardFlag) {
	$(".register div.desc").css("opacity",0); 
	if (options.nextSlide == 0) {
		$('#prev2').hide();
		$('#next2').hide();
		$('#count2').hide();
	}
}

function onAfter (currSlideElement, nextSlideElement, options, forwardFlag) {
	$(".register div.desc").animate( { opacity:1 }, { duration: 1500 });
	var count = options.currSlide + ' / ' + (options.slideCount-1);
	$('#count2').html(count);
	if (options.currSlide > 0) {
		$('#prev2').show();
		$('#count2').show();
		$('#next2').show();
	}
}

