

//MM_preloadImages('Resources/Images/nav_over.gif');


function sifrHeadline(ref,divID){
    var flashvars = {};
    var params = {};
    var attributes = {};
    flashvars.titleText = ref;
    params.wmode = 'transparent';
    swfobject.embedSWF("Resources/SWF/sifr_Headline_960x30.swf", "flashheadline" + divID, "900", "30", "9.0.0", false, flashvars, params, attributes);
}

function sifrSectionCR(ref,divID){
    var flashvars = {};
    var params = {};
    var attributes = {};
    flashvars.titleText = ref;
    params.wmode = 'transparent';
    swfobject.embedSWF("Resources/SWF/sifr_SectionHeadline_720x45.swf", "flashsection" + divID, "720", "45", "9.0.0", false, flashvars, params, attributes);
}

function sifrSectionC(ref,divID){
    var flashvars = {};
    var params = {};
    var attributes = {};
    flashvars.titleText = ref;
    params.wmode = 'transparent';
    swfobject.embedSWF("Resources/SWF/sifr_SectionHeadline_460x45.swf", "flashsection" + divID, "460", "45", "9.0.0", false, flashvars, params, attributes);
}

function sifrSectionLCR(ref,divID){
    var flashvars = {};
    var params = {};
    var attributes = {};
    flashvars.titleText = ref;
    params.wmode = 'transparent';
    swfobject.embedSWF("Resources/SWF/sifr_SectionHeadlineNoBorder_460x45.swf", "flashsection" + divID, "460", "45", "9.0.0", false, flashvars, params, attributes);
}

function sifrSectionNPLCR(ref,divID){
    var flashvars = {};
    var params = {};
    var attributes = {};
    flashvars.titleText = ref;
    params.wmode = 'transparent';
    swfobject.embedSWF("Resources/SWF/sifr_SectionHeadlineNoPadding_460x45.swf", "flashsection" + divID, "460", "45", "9.0.0", false, flashvars, params, attributes);
}

function showModal(ref){
    
    if (document.getElementById(ref).style.display == "block"){
        document.getElementById(ref).style.display = "none";
        document.getElementById('modalSubmission').style.display = "none";
    }else{
        document.getElementById(ref).style.top = getScrollY();
        document.getElementById(ref).style.display = "block";
        document.getElementById('modalSubmission').style.display = "block";
        window.onscroll = function () { 
            document.getElementById('modalSubmission').style.top = getScrollY(); 
            document.getElementById('Footer').style.top = getScrollFooter(130) + "px";
            document.getElementById('FooterMenu').style.top = getScrollFooter(130) + "px";
            document.getElementById('FooterLogo').style.top = getScrollFooter(320) + "px";
        };
    }
}

function Modal_Open(ref){
    document.getElementById(ref).style.top = getScrollY();
    document.getElementById(ref).style.display = "block";
    window.onscroll = function () { document.getElementById(ref).style.top = getScrollY(); };
}

function ModalFixed_Open(ref){
    document.getElementById(ref).style.top = getScrollY();
    document.getElementById(ref).style.display = "block";
}

function Modal_Close(ref){
    document.getElementById(ref).style.display = "none";
}

function getScrollY(){
    scrollY = 0;
    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }
    return scrollY + "px";
}

function hideBrand(ref){
    document.getElementById(ref + "_alt").style.display = "none";
    document.getElementById(ref).style.display = "block";
}

function showBrand(ref){
    document.getElementById(ref).style.display = "none";
    document.getElementById(ref + "_alt").style.display = "block";
}

function showRightColumn(ref,count){
    
    var divOn
    var divOff
    for (i=1;i<(count+1);i++){
        divOff = "id" + i;
        divOn = "id" + i + "_on";
        if (divOff == ref){
            document.getElementById(divOn).style.display = "block";
            document.getElementById(divOff).style.display = "none";
        }else{
            document.getElementById(divOn).style.display = "none";
            document.getElementById(divOff).style.display = "block";
        }
    }
    
}

function newsExpandArticle(id)
{
    var articleID = '#Article' + id;
    var imageID = '#ImgBtn' + id;
    if ($(articleID).is(':hidden'))
    {
        $(articleID).slideDown(600);
        $(imageID).attr('src', 'Resources/Images/btn_collapse.gif');
    }
    else
    {
        $(articleID).slideUp(600);
        $(imageID).attr('src', 'Resources/Images/btn_expand.gif');
    }
    
}

function brandToggle(id){
    var brandID = '#Brand' + id;
    var imageID = '#ImgBtn' + id;
    if ($(brandID).is(':hidden')){
        $(brandID).slideDown(600);
        $(imageID).attr('src', 'Resources/Images/btn_collapse.gif');
    }else{
        $(brandID).slideUp(600);
        $(imageID).attr('src', 'Resources/Images/btn_expand.gif');
    }
}

// called by onclick of any link that launches the overlay window
function initializeOverlay(defaultTab,overview,slideshow,video)
{
    $("#hDefaultTab").val(defaultTab);
    $("#hGeneralOverview").val(overview);
    $("#hSlideshow").val(slideshow);
    $("#hVideo").val(video);
}

function showFancyPopupFromFlex(caseStudyName, defaultTab, overview, slideshow, video) {   
    // Setup tabs of popup
    initializeOverlay(defaultTab, overview, slideshow, video);
    
    // Create the link for the content of FancyBox!
    var link = 'CaseStudyOverlay_' + caseStudyName + '.aspx';
    
    // Create and show our FancyBox!
    $.fancybox(
		{
        	'hideOnContentClick': false,
		    'showCloseButton': false,
		    'overlayOpacity': 0.6,
		    'overlayColor': '#000',
		    'href': link
		}
	);

} 

function toggleLanguageBox() {  
    if ($('#UtilityNavInner .UtilityLanguages > ul').css('height') == 'auto') {
        $('#UtilityNavInner .UtilityLanguages > ul').css('height', '25px');
    } else {
        $('#UtilityNavInner .UtilityLanguages > ul').css('height', 'auto');
    }
    
    return false;
}

function changeLanguage() {
    var selectedLanguage = $(this).attr('rel');
    // DO SOMETHING WITH THE SELECTED LANGUAGE
    
    switch(selectedLanguage)
    {
        case 'english':
            window.location = '/Index.aspx';
            break;
        case 'mandarin':
            window.location = '/Mandarin/Index.aspx';
            break;
        case 'portugese':
            window.location = '/Portuguese/Index.aspx';
            break;
        case 'spanish':
            window.location = '/Spanish/Index.aspx';
            break;
        case 'german':
            window.location = '/German/Index.aspx';
            break;
        case 'french':
            window.location = '/French/Index.aspx';
            break;
        case 'dutch':
            window.location = '/Dutch/Index.aspx';
            break;
    }
    
    $('#UtilityNavInner .UtilityLanguages li.first').removeClass('first');
    $(this).parent('li').prependTo('#UtilityNavInner .UtilityLanguages > ul').attr('class', 'first').find('a').click();
    return false;
}

$(document).ready(function() {
    $('#UtilityNavInner .UtilityLanguages > a, #UtilityNavInner .UtilityLanguages li.first a').live('click',toggleLanguageBox);
    $('#UtilityNavInner .UtilityLanguages li[class!=first] a').live('click', changeLanguage);
    
    $.ajax({ url: "/PreloadCaseStudyImages.aspx",
             data: "",
             dataType: 'json',
             error: function(xhr, status, error) { console.log("Error: " + status); },
             type: 'GET',
             success: function(data) {
                for (var i = 0; i < data.length; i++)
                {
                    MM_preloadImages(data[i]);
                }
             }
    });
});
