jQuery.noConflict();

var inspiracjeStarted = false;
var plakatyRestStarted = false;
var filmyStarted = false;
var filmyStopped = false;

function initMediaBox(){
    jQuery("#media-tabs").tabs({
    	select: function(event, ui) {
		var tabui = jQuery(ui.tab).attr("href").substr(1);
    		if (inspiracjeStarted == false) {
    			inspiracjeStarted = true;
    			setTimeout(jQuery.proxy(function() {
    					initInspiracje();
    	            },this),500);
    		}
    		if (plakatyRestStarted == false) {
    			plakatyRestStarted = true;
    			setTimeout(jQuery.proxy(function() {
    				initPlakatyRest();
                	},this),500);
    		} 
    		if (jQuery(ui.tab).attr("href") == "#filmy-tab" && filmyStarted == false) {
    			filmyStarted = true;
    			initFilmy();
    		} else if (jQuery(ui.tab).attr("href") == "#filmy-tab" && filmyStarted == true) { 
    			filmyStopped = false;
    			reloadYTplayer();
    		} else if (jQuery(ui.tab).attr("href") != "#filmy-tab" && filmyStarted == true && filmyStopped == false) {
    			filmyStopped = true;
    			stopFilmy();
    		}
    		setTimeout(jQuery.proxy(function() {
			startStopScroll(tabui);
               	},this),500);
    	}
    });
    jQuery("#media-tabs ul.ui-tabs-nav li").each(function(index){
		jQuery(document.createElement('li')).css({
			'background-image': 'url(http://media.travelone.pl/imgs/sprites/backgroundy.jpg)',
			'background-position':' 0 -304px',
			'background-repeat':' no-repeat',
			'float': 'left',
			'height': '24px',
			'width': '1px'
		}).insertAfter(this);
	});
	jQuery("div[id='plakaty-tab-1'] .scrollable").scrollable({
	   circular: true,
	   mousewheel: true,
	   onSeek: function(event, index) {
	       var poster_link =  jQuery("#plakaty-1 a#poster_link_"+index).attr("href");
	       jQuery("a#poster_more_button-1").attr("href",poster_link);
	   }
	}).navigator().autoscroll({
	   interval: 10000		
    });
}

function initInspiracje(){
	jQuery("#inspiracje-tab .scrollable").scrollable({
		   circular: true,
		   mousewheel: true,
		   onSeek: function(event, index) {
		       var poster_link =  jQuery("a#insp_link_"+index).attr("href");
		       var poster_link2 =  jQuery("a#insp_link2_"+index).attr("href");
		       jQuery("a#insp_more_button").attr("href",poster_link2);
		       jQuery("a#insp_oferty_button").attr("href",poster_link);
		   }
		}).navigator();
}

function initPlakatyRest() {
	jQuery("div[id^='plakaty-tab-'][id!='plakaty-tab-1'] .scrollable").each(function() {
		var identpl = jQuery(this).attr('id');
		var ident = identpl.substr(8);
		initScrollRest(ident);
	});
}

function initScrollRest(idplakat) {
	var plid='plakaty-tab-'+idplakat;
	jQuery("div[id='" + plid + "'] .scrollable").scrollable({
	   circular: true,
	   mousewheel: true,
	   onSeek: function(event, index) {
	       var poster_link =  jQuery("#plakaty-" + idplakat + " a#poster_link_"+index).attr("href");
	       jQuery("a#poster_more_button-" + idplakat).attr("href",poster_link);
	   }
	}).navigator().autoscroll({
	   interval: 10000		
    });
}

function startStopScroll(tabui) {
	if(tabui != 'filmy-tab'){
		jQuery("div[id='"+tabui+"'] .scrollable").data("scrollable").play();
	}
	jQuery("div[id^='plakaty-tab-'][id!='"+tabui+"'] .scrollable").each(function(index){
		jQuery(this).data("scrollable").stop();
	});
}

