//jQuery.noConflict();

var myPosters;
var searchRegion;
var MAP_SET_FROM_TOP = 1;
var MAP_SET_FROM_MAP = 2;
var MAP_SET_DEFAULT = 0;
var MAP_FLAG = MAP_SET_FROM_TOP = 1;;

// wywolywana jest z mapki flash
function setAllFromMap(locidValue){
	if (MAP_FLAG != MAP_SET_FROM_TOP) {
		if (locidValue == "START") {
			setContentTopOffers("");
			setSearchRegion("");
		}
		else {
			setContentTopOffers(locidValue);
			setSearchRegion(locidValue);
		}
		MAP_FLAG = MAP_SET_FROM_MAP;
	}else
		MAP_FLAG = MAP_SET_DEFAULT;
}





function initSearcher(){
    jQuery("#searcher-tabs").tabs();
	jQuery("#searcher-tabs ul.ui-tabs-nav li").each(function(index){
		jQuery(document.createElement('li')).css({ width:"1px", "background-color":"#0FB900", height:"22px" }).insertAfter(this);
	});
	jQuery("#searcher-tabs ul.ui-tabs-nav li:first a").addClass("corner-top-left");
	
	/* Zmiana URLi */
	if (varArray["panstwoID"] == 'skyone') {
		jQuery("#searcher-tabs ul.ui-tabs-nav li").children().each(function(id){
			if(jQuery(this).html() == 'Wycieczki'){
				jQuery(this).attr('href','http://www.travelone.pl/#searcher-tabs-1');
			}else if(jQuery(this).html() == 'Narty'){
				jQuery(this).attr('href','http://www.skione.pl/#searcher-tabs-1');
			}else if(jQuery(this).html() == 'Bilety lotnicze'){
				jQuery("#searcher-tabs").tabs('select',id);
				jQuery(this).attr('href','http://www.skyone.pl/#searcher-tabs-1');
			}else if(jQuery(this).html() == 'Noclegi'){
				jQuery(this).attr('href','http://www.hotelone.pl/#searcher-tabs-1');
			};
		});
		jQuery("#searcher-tabs").bind('tabsselect', function(event, ui) {
			if (jQuery(ui.tab).html() == 'Wycieczki')
				window.location = 'http://www.travelone.pl';
			else if (jQuery(ui.tab).html() == 'Narty')
				window.location = 'http://www.skione.pl';
			else if (jQuery(ui.tab).html() == 'Bilety lotnicze')
				window.location = 'http://www.skyone.pl';
			else if (jQuery(ui.tab).html() == 'Noclegi')
				window.location = 'http://www.hotelone.pl';
		});
	} else {
		jQuery("#searcher-tabs ul.ui-tabs-nav li").children().each(function(id){
			if(jQuery(this).html() == 'Wycieczki'){
				jQuery(this).attr('href','http://www.' + varArray["serwis"] + '/#searcher-tabs-1');
			}else if(jQuery(this).html() == 'Narty'){
				jQuery(this).attr('href','http://www.narty.' + varArray["serwis"] + '/#searcher-tabs-1');
			}else if(jQuery(this).html() == 'Bilety lotnicze'){
				jQuery("#searcher-tabs").tabs('select',id);
				jQuery(this).attr('href','http://www.bilety-lotnicze.' + varArray["serwis"] + '/#searcher-tabs-1');
			}else if(jQuery(this).html() == 'Noclegi'){
				jQuery(this).attr('href','http://www.hotele.' + varArray["serwis"] + '/#searcher-tabs-1');
			};			
			});
			jQuery("#searcher-tabs").bind('tabsselect', function(event, ui){
				if(jQuery(ui.tab).html() == 'Wycieczki')
					window.location='http://www.' + varArray["serwis"];
				else if(jQuery(ui.tab).html() == 'Narty')
					window.location='http://www.narty.' + varArray["serwis"];
				else if (jQuery(ui.tab).html() == 'Bilety lotnicze')
					window.location='http://www.bilety-lotnicze.' + varArray["serwis"];
				else if (jQuery(ui.tab).html() == 'Noclegi')
					window.location='http://www.hotele.' + varArray["serwis"];
			});	
	}
	
}

// wywolywana jest z arkusza XSL plakatow, na poziomie JS nie wiadomo ile plakatow bedzie prezentowanych 
function loadPosters(countOfPosters){
    jQuery(window).load(function(){
        allOK = false;
        if (countOfPosters >= 1) 
            allOK = true;
        if (allOK == true) {
            jQuery.getScript("/inc/js/plakaty/mootools.v1.11.js", function(){
                jQuery.getScript("/inc/js/plakaty/front.jd.gallery.js", function(){
                    var head = document.getElementsByTagName('head')[0];
                    jQuery(document.createElement('link')).attr({
                        type: 'text/css',
                        href: '/inc/css/front.jd.gallery.css',
                        rel: 'stylesheet',
                        media: 'screen'
                    }).appendTo(head);
                    myPosters = new gallery($('myGallery'), {
                        imageSelector: "div.full",
                        thumbnailSelector: "div.thumbnail",
                        timed: allOK,
                        showCarousel: !jQuery.browser.msie()
                    });
                    jQuery("#posters-header-lArrow").removeClass("disable-lArrow");
                    jQuery("#posters-header-lArrow").addClass("enable-lArrow");
                    jQuery("#posters-header-lArrow").click(function(){
                        myPosters.stopSliding();
                        myPosters.prevItem();
                    });
                    jQuery("#posters-header-rArrow").removeClass("disable-rArrow");
                    jQuery("#posters-header-rArrow").addClass("enable-rArrow");
                    jQuery("#posters-header-rArrow").click(function(){
                        myPosters.stopSliding();
                        myPosters.nextItem();
                    });
                    jQuery("#posters-header-show").removeClass("disable-carousel");
					if (!jQuery.browser.msie()){
						jQuery("#posters-header-show").addClass("enable-carousel");
					}
					jQuery("#posters-header-show").click(function(){
                        myPosters.carouselContainer.clearTimer();
                        myPosters.toggleCarousel();
                    });
                    jQuery(".posters-header-iterator").each(function(){
                        jQuery(this).click(function(){
                            myId = this.getAttribute("id");
                            myPosters.goTo(new Number(myId.substring(myId.length - 1, myId.length)));
                        });
                        
                    })
                })
            })
        }
    }) //end load
}

function loadMain(){
    var params = {
        quality: "high",
        allowscriptaccess: "always",
		wmode: "transparent"
    };
	if(varArray["panstwoID"]=="twojewakacje")
    	flashFileName="http://www.travelone.pl/flash/maps/mapa_swiata.swf";
	else
		flashFileName = "/flash/maps/" + varArray["panstwoID"] + ".swf";
	swfobject.embedSWF(flashFileName, "maps-box-main", "372", "268", "9.0.0", "", "", params, "");
	
	if (varArray["panstwoID"] == "grecja") {
		jQuery("#maps-tabs").tabs('select',1);
		jQuery("#maps-tabs").tabs('disable',0);
		jQuery("#maps-tabs").bind('tabsselect', function(event, ui){
			if (ui.index == 1) 
				jQuery("#maps-box-main")[0].SetVariable("showByTabs", "lokacje");
			else 
				if (ui.index == 2) 
					jQuery("#maps-box-main")[0].SetVariable("showByTabs", "osrodki");
		});
	}
}

function readyMain(){
    initSearcher();
    jQuery("#media-tabs").tabs();
	jQuery("#maps-tabs").tabs();
	
	jQuery("#media-tabs ul.ui-tabs-nav li, #maps-tabs ul.ui-tabs-nav li").each(function(index){
		jQuery(document.createElement('li')).css({ width:"1px", "background-color":"#ffffff", height:"22px" }).insertAfter(this);
	});
	jQuery("#media-tabs ul.ui-tabs-nav li:first a, #maps-tabs ul.ui-tabs-nav li:first a").addClass("corner-top-left");

}
