//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-image":"url('/imgs/skyone/sky_backgroundy.jpg')", height:"24px", "background-image":"url('/imgs/skyone/sky_backgroundy.jpg')", "background-position":"0pt -304px", "float":"left", "background-repeat":"no-repeat" }).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"];
			});	
	}
	
}

function loadPosters() {}

function loadMain(){
    var params = {
        quality: "high",
        allowscriptaccess: "always",
		wmode: "transparent"
    };
	if(varArray["panstwoID"]=="twojewakacje")
    	flashFileName="http://www." + varArray["serwis"] +"/flash/maps/mapa_swiata.swf";
	else
		flashFileName = "/flash/maps/" + varArray["panstwoID"] + ".swf";
	swfobject.embedSWF(flashFileName, "maps-box-main", "372", "268", "9.0.0", "", "", params, "");
	
}

function readyMain(){
    initSearcher();
    initDatePicker1();
    initDatePicker2();
    /*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");
	*/
	initMediaBox();
	jQuery(".sky_left_part .scrollable").scrollable({
		circular: true,
           mousewheel: true	
	})/*.navigator().autoscroll({
           interval: 5000
    })*/;
	jQuery(".przeloty_main_box input[name='przelot']")[0].checked = 1;
	jQuery("#one_way").val('N');
	jQuery(".przeloty_main_box input[name='przelot']").change(
		function()
		{
				if (jQuery(".przeloty_main_box input[name='przelot']:checked").val() == '1') {
					jQuery("#one_way").val('N');
					//jQuery("#miasto_d").removeAttr('disabled');
					//jQuery("#miasto_d").next().next().show();
					jQuery("#datepicker2").removeAttr('disabled');
					jQuery("#datepicker2").next().show();
				} else {
					jQuery("#one_way").val('Y');
					//jQuery("#miasto_d").attr('disabled', '1');
					//jQuery("#miasto_d").next().next().hide();
					jQuery("#datepicker2").attr('disabled', '1');
					jQuery("#datepicker2").next().hide();
				}
		});

	jQuery(".sky_rozwin_button").click(function() {
		jQuery(this).hide();
		jQuery(".sky_wysz_zwinieta .sky_szukaj_button").hide();
		jQuery(".sky_zwin_button").show();	
		jQuery(".sky_wysz_rozwinieta").slideDown();
		jQuery("#mlodziez").show();	
		jQuery("#seniorzy").show();	
	});
	jQuery(".sky_zwin_button").click(function() {
		jQuery(this).hide();
		jQuery("#mlodziez").hide();	
		jQuery("#seniorzy").hide();	
		jQuery(".sky_rozwin_button").show();	
		jQuery(".sky_wysz_zwinieta .sky_szukaj_button").show();
		jQuery(".sky_wysz_rozwinieta").slideUp();
	});
	jQuery(".sky_newsletterbox input[name='email']").focus(function(){this.value = "";})
	jQuery(".sky_newsletterbox input[name='email']").blur(function(){if(this.value=="") this.value = "podaj adres e-mail";})
}

function initDatePicker1(){
        jQuery("#datepicker1").datepicker({
           showOn: "both",
           changeMonth: true,
           changeYear: true,
           buttonImage: "/imgs/skyone/kalendarz.jpg",
           buttonImageOnly: true,
           buttonText: "wybierz datę",
           dateFormat: 'yy-mm-dd',
           constrainInput: true,
           onSelect: function(selectedDate) {
                sd = selectedDate.substring(6,7) == "-" ? selectedDate.substring(0,5)+"0"+selectedDate.substring(5,10) : selectedDate;
                sd = sd.length < 10 ? sd.substring(0,8)+"0"+sd.substring(8,10) : sd;
                jQuery("#search-date-s1").text(sd);
                jQuery("#search-date-s1").attr("title",sd);
                jQuery("#search-date-cal1 option[value='"+ sd +"']").attr('selected','selected');
                jQuery("#search-date1 option[value='"+ sd +"']").attr('selected','selected');
           }
        });
	var currDate1 = new Date();
        jQuery("#datepicker1").datepicker("setDate", new Date(currDate1.getTime() + 7 * 24 * 60 * 60 * 1000));
}

function initDatePicker2(){
        jQuery("#datepicker2").datepicker({
           showOn: "both",
           changeMonth: true,
           changeYear: true,
           buttonImage: "/imgs/skyone/kalendarz.jpg",
           buttonImageOnly: true,
           buttonText: "wybierz datę",
           dateFormat: 'yy-mm-dd',
           constrainInput: true,
           onSelect: function(selectedDate) {
                sd = selectedDate.substring(6,7) == "-" ? selectedDate.substring(0,5)+"0"+selectedDate.substring(5,10) : selectedDate;
                sd = sd.length < 10 ? sd.substring(0,8)+"0"+sd.substring(8,10) : sd;
                jQuery("#search-date-s2").text(sd);
                jQuery("#search-date-s2").attr("title",sd);
                jQuery("#search-date-cal2 option[value='"+ sd +"']").attr('selected','selected');
                jQuery("#search-date2 option[value='"+ sd +"']").attr('selected','selected');
           }
        });
	var currDate2 = new Date();
        jQuery("#datepicker2").datepicker("setDate", new Date(currDate2.getTime() + 14 * 24 * 60 * 60 * 1000));
}

