﻿function hasFlash() {
    var playerVersion = swfobject.getFlashPlayerVersion();
    return !(playerVersion.major == 0 && playerVersion.minor == 0 && playerVersion.release == 0);
}

function detectFlash(rewriteUrl) {    
    var isHomePage=false;
    rewriteUrl=rewriteUrl.replace(/\//, "");
    isHomePage = isHomePage || (window.location.pathname.search(/^\/$/)!=-1) || (window.location.pathname.search(/^\/index\.aspx/i)!=-1) || (window.location.pathname.search(/^\/default\.aspx/i)!=-1);
    if(isHomePage) {        
        return;
    }
    
    if (window.location.href.indexOf("localhost") >= 0) {
      return;
    }

    var flashModeInput = document.createElement('input');    
    flashModeInput.setAttribute('type', 'hidden');
    flashModeInput.setAttribute('id', 'flashMode');
    flashModeInput.setAttribute('name', 'flashMode');
    
    var anchorInput = document.createElement('input');   
       
    anchorInput.setAttribute('type', 'hidden');
    anchorInput.setAttribute('id', 'anchor');
    anchorInput.setAttribute('name', 'anchor');
    
    var currentUrl = document.location.href;
    var hasAnchor = currentUrl.indexOf("#");  
              
    if (hasAnchor == -1) {
        anchorInput.setAttribute('value', 'hasflash');
    } else {
        anchorInput.setAttribute('value', currentUrl.substring(currentUrl.indexOf("#") + 1));
    }      
      
    
    
    var alwaysADA = false;
    var adaOnlyUrls = new Array("checkout", "Checkout", "MyAccount", "AccountManagement", "RetailLocator","Account","Help","About","Experiences","MrTaylorsStore");
    
    for (i=0; i<adaOnlyUrls.length; i++) {
        if (window.location.href.indexOf(adaOnlyUrls[i]) != -1) {
            alwaysADA = true;
        }
    }
    
    var redirectUrlInput = document.createElement('input');   
       
    redirectUrlInput.setAttribute('type', 'hidden');
    redirectUrlInput.setAttribute('id', 'redirectUrlInput');
    redirectUrlInput.setAttribute('name', 'redirectUrlInput');
    redirectUrlInput.setAttribute('value', rewriteUrl);
    
    if (!alwaysADA) {
    /*
        $("FORM").append(anchorInput); 
    
        if (hasFlash()) {
            flashModeInput.setAttribute('value', '1');
            $("FORM").append(flashModeInput);                   
        } else {
            flashModeInput.setAttribute('value', '0');
            $("FORM").append(flashModeInput);                               
        }
        //$("FORM").submit();
        */
        
        var hasQueryString = (rewriteUrl.indexOf("?")!=-1);
        if(swfobject.getFlashPlayerVersion().major > 0) {
            if(!hasQueryString) {        
                window.location.href="/#/"+rewriteUrl;
            } else {
                var urlParts = rewriteUrl.split("?");                                        
                window.location.href="/?"+urlParts[1]+"#/"+urlParts[0];            
            }
        }
    }
}

function showAltView(newImg) {
    $('#prodShotL').attr({src : newImg});
}

function OpenOverLay() {
    if(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
        
        $('.OverLayBg').width($(window).width());
        $('.OverLayBg').height($(window).height());
        $('.OverLayContentShell').width($(window).width());
        $('.OverLayContentShell').height($(window).height());
    }
    $('.OverLayBg').show();
    
    
    $('.OverLayContentShell').show();
    
}

function OpenOverLayById(overLayBg,overlayContentShell) {
    if(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) {
        
        $('#'+overLayBg).width($(window).width());
        $('#'+overLayBg).height($(window).height());
        $('#'+overlayContentShell).width($(window).width());
        $('#'+overlayContentShell).height($(window).height());
    }
    $('#'+overLayBg).show();
    
    
    $('#'+overlayContentShell).show();
    
}

function CloseOverLayById(overLayBg,overlayContentShell) {    
    $('#'+overLayBg).hide();        
    $('#'+overlayContentShell).hide();    
}

function CloseOverLay() {
    $('.OverLayBg').hide();        
    $('.OverLayContentShell').hide();
}