﻿$(document).ready(function(){
	$("#video").fancybox({ 
	'width': 578, 
	'height': 386,
	'titleShow' : false,
	'type': 'swf',
	'swf' : { allowFullScreen : 'true' }
	});
	
    $("#topLinksInner a:first").css("background","none");
    $("#footerLinks a:first").css("background","none");
    $("#footerLinks a:first").css("padding-left","0");
    addClassSelected();
    divEmpty(".HomeSectionBottom");
    attrId(".blocFAQ");
    if($("#rightColumn div.title").size() > 0){
      $("#centerColumn").css("width","732px");  
      $("#rightColumn").css("width","220px");
     // $("#rightColumn .rightContent:last").ccs("background","none");
    } else {
      $("#centerColumn").css("width","732px");  
      $("#rightColumn").css("width","0px");
    }
    $(document).pngFix();
    
    alignImageForDataList();
    $('.rightContent .rightContent:has(.opeqBrefBg)').css('margin-bottom', '12px');
}); 

function alignImageForDataList() {
    $(".dataListImage tr").each(function(i) {
        $(this).children('td:eq(0)').attr("style", "text-align:center;");
        $(this).children('td:eq(1)').attr("style", "text-align:center;");
        $(this).children('td:eq(2)').attr("style", "text-align:center;");
    });
}

function addClassSelected (){
   if ($("#menuInner ul li a.selected").size() > 0)
    {
      $("#menuInner ul li a.selected").eq(0).parent().addClass("selected"); 
      $("<div id='arrowMenu'><img src='images/spc.gif'></div>").appendTo($("#menuInner ul li a.selected").eq(0).parent());
      leftPosition = ($("#menuInner ul li a.selected").eq(0).parent().width()/2-7)+"px";
      $("#arrowMenu").css("left",leftPosition);
    }
}


function liMenuOver(object){
    if(!$(object).hasClass("selected")){
        $(object).addClass("hover");
        //$("<div class='arrowMenu'><img src='images/spc.gif'></div>").appendTo($(object));
        leftPosition = ($(object).width()/2-7)+"px";
        $(".arrowMenu").css("left",leftPosition); 
    }
}

function liMenuOut(object){
    if(!$(object).hasClass("selected")){
        $(object).removeClass("hover");
        $(".arrowMenu").css("display","none"); 
    }
}

function divEmpty(object){
	$(object).each(function(){
		if(!$(this).children().length>0){
		    $(this).css("border-top","none");
		}
	});
}


function attrId(object){
		objId = 1;
		$(object).each(function(){
			$(this).attr("id",objId);
			objId = objId + 1;
		});
}

function displayBloc(id,classToDisplay){
    var stringClass = " ."+classToDisplay;
    var stringId = "#"+id+" ."+classToDisplay;
    $(stringClass).css("display","none");
    $(stringId).css("display","block");
}

function displayBloc(idAnswer,idImageOn,idImageOff, classSection, classImageOn, classImageOff){
    if ($('#'+idAnswer).css("display") == "none")
    {
        $('.'+classSection).css("display","none");        
        $('.'+classImageOn).css("display","block");
        $('.'+classImageOff).css("display","none"); 
        
        $('#'+idAnswer).css("display","block");
        $('#'+idImageOn).css("display","none");
        $('#'+idImageOff).css("display","block");
    }
    else
    {
        $('#'+idAnswer).css("display","none");
        $('#'+idImageOn).css("display","block");
        $('#'+idImageOff).css("display","none");    
    }
}


$(document).ready(function() {
    showing = $('.DidYouKnowItems div.DidYouKnowItem:first'); // Initiate the 'showing' variable as the first rotating_item
    if (showing.siblings('div').length > 0) {
        showing.siblings('div').hide(); // Hide all other rotating_items
        setInterval("hide_current_item(showing)", 10000); // Set the rotate time to 10 seconds
    }
});

// Below is the code that picks an item at random to display
$.jQueryRandom = 0;
$.extend(jQuery.expr[":"], {
    random: function(a, i, m, r) {
        if (i == 0) {
            $.jQueryRandom = Math.floor(Math.random() * r.length);
        };
        return i == $.jQueryRandom;
    }
});
// fade-in fix from http://www.kevinleary.net/jquery-fadein-fadeout-problems-in-internet-explorer/
(function($) {
    $.fn.customFadeIn = function(speed, callback) {
        $(this).fadeIn(speed, function() {
            if (jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };
    $.fn.customFadeOut = function(speed, callback) {
        $(this).fadeOut(speed, function() {
            if (jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if (callback != undefined)
                callback();
        });
    };
})(jQuery);

// The below function repeatedly gets called, to do the rotating
function hide_current_item(t) {
    jQuery(t).customFadeOut('slow', function() { show_next_item(t); });
}

function show_next_item(t) {
    var next_rotating_item = $(t).siblings('.DidYouKnowItem:random');
    if (!next_rotating_item.attr('class')) {
        next_rotating_item = $('.DidYouKnowItems div.DidYouKnowItem:first');
    }
    next_rotating_item.customFadeIn('slow');

    showing = next_rotating_item;
}

