jQuery.fn.toggleText = function(a, b) {
	return this.each(function() {
		jQuery(this).text(jQuery(this).text() == a ? b : a);
	});
};


$(function() {

    /*
    $('.LanguageContainer').hover(function() {
    $(this).toggleClass("active");
    });
    */

    $('.RegionCampaign10Box').cycle({
        fx: 'fade',
        speed: 'fast',
        timeout: 3000,
        delay: -2000,
        pause: 1,
        pager: '#RegionCampaign10BoxpNavigation'
    });

    $("h1.divHide").click(function() {
        $(this).parent().children('.hideable').toggle();
        $(this).toggleClass('divShow');
    });

    $("a.divHide").click(function() {
        $(this).parent().children('.hideable').toggle();
        $(this).toggleClass('divShow');
    });

    $('span.flashbox').flash(null, { version: 8 }, function(htmlOptions) {
        var $this = $(this);
        var params = $this.attr('rel').split('|');
        htmlOptions.src = params[0];
        htmlOptions.width = params[1];
        htmlOptions.height = params[2];
        htmlOptions.wmode = 'transparent';
        this.innerHTML = '<div class="alt">' + this.innerHTML + '</div>';
        $this.addClass('flash-replaced').prepend($.fn.flash.transform(htmlOptions));
    });

    $("ul.tabs").tabs("div.panes > div.pane", { history: true });

    $(".iframe640x480").fancybox({ 'frameWidth': 640, 'frameHeight': 480, 'overlayShow': true });
    $(".iframe480x360").fancybox({ 'frameWidth': 480, 'frameHeight': 240, 'overlayShow': true });
    $(".iframe750x480").fancybox({ 'frameWidth': 750, 'frameHeight': 480, 'overlayShow': true });
    $(".iframe820x480").fancybox({ 'frameWidth': 820, 'frameHeight': 480, 'overlayShow': true });
    $(".tooltipper").tooltip();


    $('.cmbRoom').change(function() {
        var selIndex;
        var items = [1, 2, 3, 4];
        selIndex = $(".cmbRoom").val();

        $.each(items, function() {

            $("tr.trRoom" + selIndex + " .trPax1").show();

            if (this > selIndex) {
                $("div.Room" + this).hide();
                $("tr.trRoom" + this).hide();

            }
            if (this <= selIndex) {
                $("div.Room" + this).show();
                $("tr.trRoom" + this).show();
            }

        });

    });

    $('.cmbAdults1').change(function() {
        var selIndex = $(".cmbAdults1").val();
        var items = [1, 2, 3, 4];

        if (selIndex != 22) {
            $.each(items, function() {

                if (this > selIndex) {
                    $("tr.trRoom1 .trPax" + this).hide();
                }
                if (this <= selIndex) {
                    $("tr.trRoom1 .trPax" + this).show();
                }

            });
        }

        if (selIndex == 22) {
            $.each(items, function() {
                if (this > 2) {
                    $("tr.trRoom1 .trPax" + this).hide();
                }
                if (this <= 2) {
                    $("tr.trRoom1 .trPax" + this).show();
                }
            });
        }

        if (selIndex == 22 || selIndex == 2) {
            $('.cmbChild1').show();
            $('.ca1').show();
        }
        else {
            $('.cmbChild1').hide();
            $('.ca1').hide();
        }

    });


    $('.cmbAdults2').change(function() {
        var selIndex = $(".cmbAdults2").val();
        var items = [1, 2, 3, 4];
        //alert(selIndex);
        if (selIndex != 22) {
            $.each(items, function() {

                if (this > selIndex) {
                    $("tr.trRoom2 .trPax" + this).hide();
                }
                if (this <= selIndex) {
                    $("tr.trRoom2 .trPax" + this).show();
                }

            });
        }

        if (selIndex == 22) {
            $.each(items, function() {
                if (this > 2) {
                    $("tr.trRoom2 .trPax" + this).hide();
                }
                if (this <= 2) {
                    $("tr.trRoom2 .trPax" + this).show();
                }
            });
        }

        if (selIndex == 22 || selIndex == 2) {
            $('.cmbChild2').show();
            $('.ca2').show();
        }
        else {
            $('.cmbChild2').hide();
            $('.ca2').hide();
        }

    });


    $('.cmbAdults3').change(function() {
        var selIndex = $(".cmbAdults3").val();
        var items = [1, 2, 3, 4];
        //alert(selIndex);
        if (selIndex != 22) {
            $.each(items, function() {

                if (this > selIndex) {
                    $("tr.trRoom3 .trPax" + this).hide();
                }
                if (this <= selIndex) {
                    $("tr.trRoom3 .trPax" + this).show();
                }

            });
        }

        if (selIndex == 22) {
            $.each(items, function() {
                if (this > 2) {
                    $("tr.trRoom3 .trPax" + this).hide();
                }
                if (this <= 2) {
                    $("tr.trRoom3 .trPax" + this).show();
                }
            });
        }

        if (selIndex == 22 || selIndex == 2) {
            $('.cmbChild3').show();
            $('.ca3').show();
        }
        else {
            $('.cmbChild3').hide();
            $('.ca3').hide();
        }

    });


    $('.cmbAdults4').change(function() {
        var selIndex = $(".cmbAdults4").val();
        var items = [1, 2, 3, 4];
        //alert(selIndex);
        if (selIndex != 22) {
            $.each(items, function() {

                if (this > selIndex) {
                    $("tr.trRoom4 .trPax" + this).hide();
                }
                if (this <= selIndex) {
                    $("tr.trRoom4 .trPax" + this).show();
                }

            });
        }

        if (selIndex == 22) {
            $.each(items, function() {
                if (this > 2) {
                    $("tr.trRoom4 .trPax" + this).hide();
                }
                if (this <= 2) {
                    $("tr.trRoom4 .trPax" + this).show();
                }
            });
        }

        if (selIndex == 22 || selIndex == 2) {
            $('.cmbChild4').show();
            $('.ca4').show();
        }
        else {
            $('.cmbChild4').hide();
            $('.ca4').hide();
        }

    });


    $('.cmbChild1').change(function() {
        var selIndex = $(".cmbChild1").val();

        if (selIndex == 0) {
            $("tr.trRoom1 .trChild").hide();
        }
        if (selIndex == 1) {
            $("tr.trRoom1 .trChild").show();
        }
    });

    $('.cmbChild2').change(function() {
        var selIndex = $(".cmbChild2").val();

        if (selIndex == 0) {
            $("tr.trRoom2 .trChild").hide();
        }
        if (selIndex == 1) {
            $("tr.trRoom2 .trChild").show();
        }
    });

    $('.cmbChild3').change(function() {
        var selIndex = $(".cmbChild3").val();

        if (selIndex == 0) {
            $("tr.trRoom3 .trChild").hide();
        }
        if (selIndex == 1) {
            $("tr.trRoom3 .trChild").show();
        }
    });

    $('.cmbChild4').change(function() {
        var selIndex = $(".cmbChild4").val();
        if (selIndex == 0) {
            $("tr.trRoom4 .trChild").hide();
        }
        if (selIndex == 1) {
            $("tr.trRoom4 .trChild").show();
        }
    });

//    $(".SearchHotel").click(function() {
//        var cmbSearchVal = $("#ctl00_HotelSearchBox_cmbSearch_text").val();
//        return false;
//        if (cmbSearchVal.indexOf("|")==-1) {
//            return false;
//        }
//        else {
//            return true;
//        }
//    });
	
	$('.FlashBoxContainer').hover(
		 function() {
			//$(this).removeClass('FlashHider');
			$(this).css("height","auto");
		 },	
		 function() {
			//$(this).addClass('FlashHider');
			$(this).css("height","124px");
		 }
	);
	
	if ($(".HotelResultHotelHeader").length > 0) {
		$("div.Main").hide();
	}
	
	$("select.cmbMarket").val('DE');

	var stringAutoComplete = "<div class='AutoCompleteLocations'>"+
		"<select class='AutoCompleteSelect'>"+
			"<option value='0'>Top Cities</option>"+
			"<option value='AMS-NL'>Amsterdam</option>" +
			"<option value='ANR-BE'>Antwerpen</option>" +
			"<option value='PEK-CN'>Peking</option>" +
			"<option value='BRUG-BE'>Brügge</option>" +
			"<option value='BCN-ES'>Barcelona</option>"+
			"<option value='BER-DE'>Berlin</option>" +
			"<option value='BRU-BE'>Brüssel</option>" +
			"<option value='CAI-EG'>Kairo</option>" +
			"<option value='CPT-ZA'>Kapstadt</option>" +
			"<option value='CGN-DE'>Köln</option>" +
			"<option value='CPH-DK'>Kopenhagen</option>" +
			"<option value='DAM-SY'>Damaskus</option>" +
			"<option value='DUBW-AE'>Dubai</option>" +
			"<option value='DUB-IE'>Dublin</option>" +
			"<option value='DUS-DE'>Düsseldorf</option>" +
			"<option value='FLR-IT'>Florenz</option>" +
			"<option value='GVA-CH'>Genf</option>" +
			"<option value='GLA-GB'>Glasgow</option>" +
			"<option value='IST-TR'>Istanbul</option>" +
			"<option value='IEV-UA'>Kiew</option>" +
			"<option value='LIS-PT'>Lissabon</option>" +
			"<option value='LAS-US'>Las Vegas</option>" +
			"<option value='LON-GB'>London</option>" +
			"<option value='LUCE-CH'>Luzerne</option>" +
			"<option value='MIL-IT'>Mailand</option>" +
			"<option value='MIA-US'>Miami</option>" +
			"<option value='MOW-RU'>Moskau</option>" +
			"<option value='MUC-DE'>München</option>" +
			"<option value='NYC-US'>New York</option>" +
			"<option value='NCE-FR'>Nizza</option>" +
			"<option value='NUE-DE'>Nürnberg</option>" +
			"<option value='ORL-US'>Orlando</option>" +
			"<option value='PAR-FR'>Paris</option>" +
			"<option value='HKT-TH'>Phuket</option>" +
			"<option value='PRG-CZ'>Prag</option>" +
			"<option value='ROM-IT'>Rom</option>" +
			"<option value='SIN-SG'>Singapore</option>" +
			"<option value='STO-SE'>Stockholm</option>" +
			"<option value='SYD-AU'>Sydney</option>" +
			"<option value='VCE-IT'>Venedig</option>" +
			"<option value='VIE-AT'>Wien</option>" +
			"<option value='WAW-PL'>Warschau</option>" +
			"<option value='ZRH-CH'>Zürich</option>" +
		"</select>"+
		"</div> "
	
	$(".AutoComplete").before(stringAutoComplete);
	$(".AutoComplete").val("Enter city name...");
	$(".AutoComplete").click(function(){
		if ($(".AutoComplete").val() == "Enter city name..."){
			$(".AutoComplete").val("");
		}
	});
	$(".AutoComplete").blur(function(){
		if ($(".AutoComplete").val() == ""){
			$(".AutoComplete").val("Enter city name...");
		}
	});	
	
	$(".AutoCompleteSelect").change(function(){
		if ($('.AutoCompleteSelect :selected').val() != 0) {
			$(".AutoComplete").val($('.AutoCompleteSelect :selected').text());
			$(".AutoComplete").next('input').val($('.AutoCompleteSelect :selected').val());
			$("#ctl00_ContentPlaceHolder1_HotelSearchBox1_ctl01").next('input').val($('.AutoCompleteSelect :selected').val());
		}
	});
	
	
	if ($(".agentlimit").length) {
		if (jQuery.trim($(".agentlimit").html()) == "") {
			$("div.Menu").hide();
		}
	}	
	
});

function ShowMessage(MessageType, MessageId) {
    $('.MessageBar').show();
    $('.MessageBar .'+MessageType).show();
    $('.MessageBar .'+MessageType).load("Message.aspx?MessageId="+MessageId);
}
