﻿$j(document).ready(function() {
    // Main Menu Selected Link
    $j('#mainNavLinks a[href]').each(function() {
        var curPage = window.location.href;
        if (curPage.indexOf(this.title) != -1 || this.href == curPage || this.href + '/default.aspx' == curPage) {
            $j(this).addClass('activeNav');
            return false;
        }
    });

    //textbox default switch
    var $inputs = $j('input[type=text][title]');
    $inputs.focus(function() {
        if (this.value == this.title) {
            this.value = '';
        }
    });
    $inputs.blur(function() {
        if (this.value.length == 0) {
            this.value = this.title;
        }
    });

    
    //mobile views
    var  isiPad = navigator.userAgent.match(/iPad/i)  != null;
    var  isiPhone = navigator.userAgent.match(/iPhone/i)  != null;
    var  isiPod = navigator.userAgent.match(/iPod/i)  != null;
    if(isiPad)
    {      
          $j("html").addClass("iPad");	      		   
          $j("body").addClass("mobileBody");	  
     }
       if(isiPhone || isiPod)
    {      
          $j("html").addClass("iPhone");	      		   
          $j("body").addClass("mobileBody");	  
     }


});

    function locateStoreByPOPZip() {
        
        //get the POP input value
        var popValue = $j('.storeLocatorPOP').val();
        var popTitle = $j('.storeLocatorPOP').attr('title');
        //redirect the page to the store locator with the querystring param	
	    //alert(popValue == popTitle);
        if (popValue != popTitle) {
            //alert('/store-locator/default.aspx?zip=' + popValue.substr(0, 10));
            window.location.href = '/store-locator/?zip=' + popValue.substr(0, 10);
        }	

    }

    function locateStoreByStep6ZipForItem(itemid,planogram) {

        //get the POP input value
        var popValue = $j('.storeLocatorStep6').val();
        var popTitle = $j('.storeLocatorStep6').attr('title');
        //redirect the page to the store locator with the querystring param         
        if (popValue != popTitle){
            window.open('/store-locator/?itemid=' + itemid + '&zip=' + popValue.substr(0, 10) + '&planogram=' + planogram);
           
        }
    }

    function locateStoreByPOPDropDownLocForItem(itemid, planogram) {
        
        //get the POP input value
        var popValue = $j('.stateProvDropDown').val();
        var popTitle = 'None';
        //redirect the page to the store locator with the querystring param	
	    //alert(popValue == popTitle);
        if (popValue != popTitle) {
            //alert('/store-locator/default.aspx?zip=' + popValue.substr(0, 10));
            window.open('/store-locator/?itemid=' + itemid + '&loc=' + popValue.substr(0, 10) + '&planogram=' + planogram);
        }

    }

/*
var videoPlayerLicenseCode = '';

switch (window.location.hostname) {
    case 'localhost':
        videoPlayerLicenseCode = 'b89f4bd520157d327f6';
        break;
    case 'staging.freedomrail.ribbitt.com':
        videoPlayerLicenseCode = '00ad082693dd5486f4d';
        break;
    case 'www.freedomrail.com':
        videoPlayerLicenseCode = 'ad193c452f744eec5a7';
        break;
    case 'freedomrail.com':
        videoPlayerLicenseCode = '24ad7254fce0aa7db83';
        break;
}

var VideoOverlay = function() {

    $j('body').append('<div id="video-modal"><div id="modal-wrapper"><div id="modal-player"></div><span class="close">CLOSE</span></div></div>');

    var overlay = $j('#video-modal').overlay({
        api: true,
        expose: {
            color: '#333',
            loadSpeed: 200,
            opacity: 0.9
        },
        onLoad: function() {
            $f('modal-player').load();
        },
        onClose: function() {
            $f('modal-player').pause(); // ie8 win7 issue
            $f('modal-player').unload();
        }
    });


    $j('a[href$=.flv]').click(function(event) {
        var videoLink = this.href;
        flowplayer('modal-player', '/common/flowplayer/flowplayer.leapfrog-3.1.5.swf', {
            key: videoPlayerLicenseCode,
            clip: {
                scaling: 'fit',
                url: videoLink,
                autoPlay: true
            },
            canvas: {
                backgroundColor: '#ffffff'
            },
            plugins: {
                controls: {
                    autoHide: 'always',
                    hideDelay: 1000
                }
            }
        });

        overlay.load();

        return false;
    });
};

*/
