$(window).load(function(){
	//LAYOUT ENHANCEMENTS
	$(".strip4 .stripItem:last").addClass("last").width(149).css("overflow","hidden");
	$(".strip3 .stripItem:last").addClass("last");
	if($("#center").height()<$("#left").height() && $(".home").size()==0){
		$("#center").height($("#left").height());
	}
	//MAP
	$("#gmap").gMap({ markers: [{ latitude: 51.087945,
                              longitude: 3.673019 }],
                              zoom:12,
                              controls: false});
    //SLIDER
    var total = 0;     
    var current = 1;
	
    $(".caseSlide").each(function(){
    $(this).hide();
    	total++;
    	$(".caseSlide:nth-child("+current+")").show();
		if($("#center").height()<$("#left").height()){
			$("#center").height($("#left").height());
		}
    });
    
    
   
    //CONTROLS
    $("#prev").click(function(){
    	if(current == 1){
    		current = total;
    		hideTheKids(current);
    	} else {
    		current--
    		hideTheKids(current);
    	}
    });
    $("#next").click(function(){
    	if(current == total){
    		current = 1;
    		hideTheKids(current);
    	} else {
    		current++
    		hideTheKids(current);
    	}
    });
    
    function hideTheKids(toshow){
   		$(".caseSlide").each(function(){
    		$(this).hide();
    		
   		});
   		 $(".caseSlide:nth-child("+toshow+")").show();
		 if($("#center").height()<$("#left").height()){
			 $("#center").height($("#left").height());
		 }
	}
	
	//TIPS SLIDER
	var totalTips = $("#tipcontent ul li").length;     
    var currentTip = 1;
	var tipSlider = $("#tipcontent ul");
	$(".prevTip").hide();
	
	$(".prevTip").click(function(){
		$(".nextTip").show();
		tipSlider.animate({marginLeft:"+=446"},500);
		currentTip--;
    	if(currentTip == 1){
			$(this).hide();
		} 
		return false;
    });
	$(".nextTip").click(function(){
		$(".prevTip").show();
		tipSlider.animate({marginLeft:"-=446"},500);
		currentTip++;
    	if(currentTip == totalTips){
			$(this).hide();
		} 
		return false;
    });
    if($.browser.msie){
        $(".safetyTrigger").live("click",function(e){
            $("#modal-overlay").show();
            $("#bluePopup").show();
            e.preventDefault();
        })

        $(".greenTrigger").live("click",function(e){
            $("#modal-overlay").show();
            $("#greenPopup").show();
            e.preventDefault();
        })

        $("#bluePopup .close").live("click",function(e){
            $("#modal-overlay").hide();
            $("#bluePopup").hide();
            e.preventDefault();
        })

        $("#greenPopup .close").live("click",function(e){
            $("#modal-overlay").hide();
            $("#greenPopup").hide();
            e.preventDefault();
        })

        $("#modal-overlay").live("click",function(e){
             $("#bluePopup").hide();
             $("#greenPopup").hide();
             $("#modal-overlay").hide();
        })
    } else {
        $(".safetyTrigger").live("click",function(e){
            $("#modal-overlay").fadeIn();
            $("#bluePopup").show("drop", { direction: "up", easing:"easeOutBack" }, 1000);
            e.preventDefault();
        })

        $(".greenTrigger").live("click",function(e){
            $("#modal-overlay").fadeIn();
            $("#greenPopup").show("drop", { direction: "up", easing:"easeOutBack" }, 1000);
            e.preventDefault();
        })

        $("#bluePopup .close").live("click",function(e){
            $("#modal-overlay").fadeOut();
            $("#bluePopup").hide("drop", { direction: "up", easing:"easeInBack" }, 1000);
            e.preventDefault();
        })

        $("#greenPopup .close").live("click",function(e){
            $("#modal-overlay").fadeOut();
            $("#greenPopup").hide("drop", { direction: "up", easing:"easeInBack" }, 1000);
            e.preventDefault();
        })

        $("#modal-overlay").live("click",function(e){
             $("#bluePopup").fadeOut();
             $("#greenPopup").fadeOut();
             $("#modal-overlay").fadeOut();
        })
    }
});
                  
               
