﻿jQuery(function ($) {

    var FixedDivs = 70;
    var FixedDivs2 = 60;
    var isResizing;
    var HeightMax = $("#hoz").height();

    $(window).resize(function () {

        var HeightWindow = $(window).height();
        var HeightToMatch;
        
        //vertical
        if (HeightWindow<HeightMax)
            {DisableVerticalMode();}
        else 
            {EnableVerticalMode(); HeightToMatch = HeightMax; }
    
    

        $('#master_container').css({ 'height': ((HeightToMatch) - FixedDivs) + 'px' });
        $('#master_wrapper').css({ 'height': ((HeightToMatch) - (FixedDivs + FixedDivs2)) + 'px' });
        $('#master_content').css({ 'height': ((HeightToMatch) - (FixedDivs + FixedDivs2)) + 'px' });

        setPaneScroll();

    });
    $(window).load(function () {
    
         var HeightWindow = $(window).height();    
         var HeightToMatch;
         
          HeightToMatch = HeightMax;
         
         //vertical
         if (HeightWindow<HeightMax)
            {DisableVerticalMode();}
         else 
            {EnableVerticalMode();}

        $('#master_container').css({ 'height': ((HeightToMatch) - FixedDivs) + 'px' });
        $('#master_wrapper').css({ 'height': ((HeightToMatch) - (FixedDivs + FixedDivs2)) + 'px' });
        $('#master_content').css({ 'height': ((HeightToMatch) - (FixedDivs + FixedDivs2)) + 'px' });

        setPaneScroll();

    });
    
    
    var DisableVerticalMode =  function () {
        $('#vertical').css({ 'marginTop': '0px' });
        $('#vertical').css({ 'top': '0' });
    
    }
    var EnableVerticalMode =  function () {
        $('#vertical').css({ 'marginTop': '-287px' });
        $('#vertical').css({ 'top': '50%' });
    
    }
    var setPaneScroll = function () {
        // IE triggers the onResize event internally when you do the stuff in this function
        // so make sure we don't enter an infinite loop and crash the browser
        if (!isResizing) {
            isResizing = true;
            $container = $('#master_wrapper');
            $pane = $('#master_content');
            //$('#ContentMaster>.jScrollPaneContainer').css({'height': $container.height() + 'px', 'width': $container.width() + 'px'});

            $('#master_wrapper>.div_center>.jScrollPaneContainer').css({ 'height': $container.height() + 'px' });
            $pane.jScrollPane({ scrollbarWidth: '10', enableKeyboardNavigation: false });

            isResizing = false;
        }
    }

});

$(document).ready(function () {

    /*START SC_COMBO*/
    $('.sc_combo').each(function (index) {
        $(this).html('<div class="sc_list">' + $(this).html() + '</div>');
    });
    $(".sc_list ul li").click(function () {
        if ($(this).find(".sc_item").html().replace(/^\s+|\s+$/g, "") != '') {
            $(this).parent("ul").parent("div").parent("div").find(".sc_selected").find(".sc_label").html($(this).find(".sc_item").html());
            $(this).parent("ul").parent("div").hide();
        }
    });
    $('.sc_combo').each(function (index) {
        $(this).prepend('<div class="sc_selected">Label</div>');
    });
    $('.sc_list ul').each(function (index) {
        $(this).prepend('<li></li>');
    });
    $('.sc_selected').each(function (index) {
        $(this).html('<div class="sc_label_left"></div><div class="sc_label">' + $(this).html() + '</div><div class="sc_label_right"></div>');
    });
    $('.sc_list ul li').each(function (index) {
        $(this).html('<div class="sc_item_left"></div><div class="sc_item">' + $(this).html() + '</div><div class="sc_item_right"></div>');
        if ($(this).attr("class") == 'selected') {
            $(this).click();
        }
    });
    $(".sc_selected").click(function () {
        $(this).parent("div").find(".sc_list").show();
    });
    /*
    $(".sc_selected").hover(function () {
        $(this).parent("div").find(".sc_list").show();
    }, function () {
    });
    */
    $(".sc_list").hover(function () {
    }, function () {
        $(this).hide();
    });
    $(".sc_list ul li").hover(function () {
        if ($(this).find(".sc_item").html().replace(/^\s+|\s+$/g, "") != '') {
            $(this).addClass("hover");
        }
    }, function () {
        $(this).removeClass("hover");
    });
    /*END SC_COMBO*/

    //------------------
    // MENU lingue
    //------------------

    $(".language li").hover(function () {    //On hover...

        var tagA = $(this).find("a");
        if ($(this).attr("class") == "active") {

        }
        else {

            $(tagA).stop().animate({ color: "#F10E00" }, { duration: 250 });
        }

    }, function () { //On hover out...
        var tagA = $(this).find("a");
        if ($(this).attr("class") == "active") {

        }
        else {
            $(tagA).stop().animate({ color: "#5B5B5B" }, { duration: 250 });
        }

    });


    $(".menufooter li.right").hover(function () {    //On hover...

        var tagA = $(this).find("a");
        if ($(tagA).attr("class") == "active") {

        }
        else {

            $(tagA).stop().animate({ color: "#F10E00" }, { duration: 250 });
        }

    }, function () { //On hover out...
        var tagA = $(this).find("a");
        if ($(tagA).attr("class") == "active") {

        }
        else {
            $(tagA).stop().animate({ color: "#4B4B4B" }, { duration: 250 });
        }

    });




    $(".menufooter li.left").hover(function () {    //On hover...

        var tagA = $(this).find("a");
        if ($(tagA).attr("class") == "active") {

        }
        else {

            $(tagA).stop().animate({ color: "#F10E00" }, { duration: 250 });
        }

    }, function () { //On hover out...
        var tagA = $(this).find("a");
        if ($(tagA).attr("class") == "active") {

        }
        else {
            $(tagA).stop().animate({ color: "#6B6B6B" }, { duration: 250 });
        }

    });


    $("#breadcrumb li").hover(function () {    //On hover...

        var tagA = $(this).find("a");
        if ($(this).attr("class") == "active") {
        }
        else {

            $(tagA).stop().animate({ color: "#F10E00" }, { duration: 250 });
        }

    }, function () { //On hover out...
        var tagA = $(this).find("a");
        if ($(this).attr("class") == "active") {
        }
        else {
            $(tagA).stop().animate({ color: "#5B5B5B" }, { duration: 250 });
        }

    });



    $(".link_box_languages").colorbox({ inline: true, href: "#box_languages" });
    $(".link_box_countries").colorbox({ inline: true, href: "#box_countries" });
    $(".link_box_credits").colorbox({ inline: true, href: "#box_credits" });
    $(".link_box_colours").colorbox({ inline: true, href: "#box_colours" });
    $(".link_box_company_informations").colorbox({ inline: true, href: "#box_company_informations" });
    // $(".link_box_privacy").colorbox({ inline: true, href: "#box_privacy" });
    $(".link_box_my_list_alert").colorbox({ inline: true, href: "#box_my_list_alert" });


    /*combo*/
    var brwVerIE = 8;
    if ($.browser.msie) {
        brwVerIE = jQuery.browser.version.substring(0, 1)
    }

    if (($.browser.msie) && (brwVerIE > 7)) {
        $(".div_corner").corner("round 5px").parent().css('padding', '1px').corner("round 5px");
    }

    if (!($.browser.msie)) {
        $(".div_corner").corner("round 5px").parent().css('padding', '1px').corner("round 5px");
    }


    $(".div_combo").hide();

    $(".div_combo_closed").hover(function () {
        //$(this).find(".div_combo").fadeIn(500);
        $(this).find(".div_combo").css({ 'display': 'block' });
        makeScrollable($(this).find(".sc_menu_wrapper"), $(this).find(".sc_menu"));
    }, function () {
        $(this).find(".div_combo").fadeOut(100);
    });

    $(".div_combo div ul li a").click(function () {
        var div_combo = $(this).parent("li").parent("ul").parent("div").parent(".div_combo");
        var div_combo_closed = div_combo.parent(".div_combo_closed");
        div_combo_closed.find(".selected_text").html($(this).html());
        div_combo.fadeOut("slow");
    });


    tooltip();

});

	
    function makeScrollable(wrapper, scrollable){
	    // Get jQuery elements
	    var wrapper = $(wrapper), scrollable = $(scrollable);
    	
	    // Hide images until they are not loaded
	    wrapper.show();
	    scrollable.hide();
    	
	    // Set function that will check if all images are loaded
	    

		    setTimeout(function(){    				
			    // Remove scrollbars
			    wrapper.css({overflow: 'hidden'});
			    scrollable.show();
			    enable();
//			    scrollable.slideToggle('slow', function(){
//			     // Animation complete.   
//                     
//                    });				
		    }, 100);	
	
   	
	    function enable(){	    			        
		    // height of area at the top at bottom, that don't respond to mousemove
		    var inactiveMargin = 99;	
		    				
		    // Cache for performance
		    var wrapperHeight = wrapper.height();
		    // Using outer height to include padding too
		    
		    var scrollableHeight = scrollable.outerHeight() + 2*inactiveMargin;
		    // Do not cache wrapperOffset, because it can change when user resizes window
		    // We could use onresize event, but it's just not worth doing that 
		    // var wrapperOffset = wrapper.offset();
		    
	    

		    //When user move mouse over menu			
		    wrapper.mousemove(function(e){
		    
     
			    var wrapperOffset = wrapper.offset();
			    var scrollableOffset = scrollable.offset();			    

			    // Scroll menu
	
			    //---------------------------------------->
			    var top = (e.pageY -  wrapperOffset.top) * (scrollableHeight - wrapperHeight) / wrapperHeight - inactiveMargin;			    			
			    
			    if (top < 0){
				    top = 0;
			    }		
			    wrapper.scrollTop(top);	
			    //---------------------------------------->
		
		    });   		

	    }	
	    
	    };

function open_popup(url, w, h) {
    var l = Math.floor((screen.width - w) / 2);
    var t = Math.floor((screen.height - h) / 2);
    window.open(url, "", "width=" + w + ",height=" + h + ",top=" + t + ",left=" + l);
}
