// Simple JavaScript Rotating Banner Using jQuery
// www.mclelun.com
var jqb_vCurrent = 0;
var jqb_vTotal = 0;
var jqb_vDuration = 5000;
var jqb_intInterval = 0;
var jqb_vGo = 1;
var jqb_vIsPause = false;
var jqb_tmp = 20;
var jqb_title;

jQuery(document).ready(function() {	
	jqb_vTotal = jQuery(".jqb_slides").children().size() -1;
	jQuery(".jqb_info").text(jQuery(".jqb_slide").attr("title"));	
	jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
			
	jQuery("#jqb_object").find(".jqb_slide").each(function(i) { 
		jqb_tmp = ((i - 1)*730) - ((jqb_vCurrent -1)*730);
		jQuery(this).animate({"left": jqb_tmp+"px"}, 500);
	});
	
	jQuery("#btn_pauseplay").click(function() {
		if(jqb_vIsPause){
			jqb_fnChange();
			jqb_vIsPause = false;
			jQuery("#btn_pauseplay").removeClass("jqb_btn_play");
			jQuery("#btn_pauseplay").addClass("jqb_btn_pause");
		} else {
			clearInterval(jqb_intInterval);
			jqb_vIsPause = true;
			jQuery("#btn_pauseplay").removeClass("jqb_btn_pause");
			jQuery("#btn_pauseplay").addClass("jqb_btn_play");
		}
	});
	jQuery("#btn_prev").click(function() {
		jqb_vGo = -1;
		jqb_fnChange();
	});
		
	jQuery("#btn_next").click(function() {
		jqb_vGo = 1;
		jqb_fnChange();
	});
});

function jqb_fnChange(){
	clearInterval(jqb_intInterval);
	jqb_intInterval = setInterval(jqb_fnLoop, jqb_vDuration);
	jqb_fnLoop();
}

function jqb_fnLoop(){
	if(jqb_vGo == 1){
		jqb_vCurrent == jqb_vTotal ? jqb_vCurrent = 0 : jqb_vCurrent++;
	} else {
		jqb_vCurrent == 0 ? jqb_vCurrent = jqb_vTotal : jqb_vCurrent--;
	}
	
	jQuery("#jqb_object").find(".jqb_slide").each(function(i) { 
		
		if(i == jqb_vCurrent){
			jqb_title = jQuery(this).attr("title");
			jQuery(".jqb_info").animate({ opacity: 'hide', "left": "-50px"}, 250,function(){
				jQuery(".jqb_info").text(jqb_title).animate({ opacity: 'show', "left": "0px"}, 500);
			});
		} 
		

		//Horizontal Scrolling
		jqb_tmp = ((i - 1)*730) - ((jqb_vCurrent -1)*730);
		jQuery(this).animate({"left": jqb_tmp+"px"}, 500);
		
		/*
		//Fade In & Fade Out
		if(i == jqb_vCurrent){
			jQuery(".jqb_info").text(jQuery(this).attr("title"));
			jQuery(this).animate({ opacity: 'show', height: 'show' }, 500);
		} else {
			jQuery(this).animate({ opacity: 'hide', height: 'hide' }, 500);
		}
		*/
		
	});


}










// What is jQuery(document).ready ? See: http://flowplayer.org/tools/documentation/basics.html#document_ready
jQuery(document).ready(function() {

// initialize scrollable together with the autoscroll plugin
var root = jQuery("#scroller").scrollable({circular: true}).autoscroll({ autoplay: true, interval: 8000 });

// provide scrollable API for the action buttons
window.api = root.data("scrollable");

	
});




window.onscroll = function()
{
    if( window.XMLHttpRequest ) {
        if (document.documentElement.scrollTop > 170 || self.pageYOffset > 170) {
            jQuery('#buy_tickets_now').css('position','fixed');
            jQuery('#buy_tickets_now').css('top','0');
        } else if (document.documentElement.scrollTop < 170 || self.pageYOffset < 170) {
            jQuery('#buy_tickets_now').css('position','absolute');
            jQuery('#buy_tickets_now').css('top','170px');
        }
    }
}
