/// <reference path="jquery-1.4.1-vsdoc.js" />
var browser = navigator.appName; //productresults, searchresults,noresults
var reportBI = true;

var _myPage = {};
_myPage.Location = window.location.href;
_myPage.ImageList = [];

$(document).ready(function() {
    $('#mainNav .mega').hoverIntent(addMega, removeMega);   //master

    InitializeWaterMark();    

    $('img').error(function() {
        var imgerr = {};
        imgerr.Source = $(this).attr('src');
        _myPage.ImageList.push(imgerr);
        
    });    

    $('#popSafeShop').jqm({ trigger: '.tgSafeShop' });     //in masterpage footer
    
    //best Sellers, product_results, featured/todays best sellers
    var hovrableImgs = $(".bestSellers .prod img,#catImgSize .prod img, #prodHm img");
    
    preloadMouseOvers(hovrableImgs);
    
    hovrableImgs.hover(function() {
            var src=$(this).attr("src");
            src = src.replace("_2)","_4)");
            $(this).attr("src",src);
		}, function() {
            var src=$(this).attr("src");
            src = src.replace("_4)","_2)");
            $(this).attr("src",src);
    });
});

function onPageShow(){
    var hovrableImgs = $(".bestSellers .prod img,#catImgSize .prod img, #prodHm img");
    hovrableImgs.each(function() {
        var src=$(this).attr("src");
        src = src.replace("_4)","_2)");
        $(this).attr("src",src);
    });
}

//preload all the hover states
function preloadMouseOvers(theImgs){

    for(var i=0;i<theImgs.length;i++){
        jQuery("<img>").attr("src", 
                             $(theImgs[i]).attr("src").replace("_2)","_4)")
                            );
    }
}

$(window).load(function() {
    DealWithBrokenImages();
});

function DealWithBrokenImages() {
    if (reportBI) {
        if (_myPage.ImageList.length > 0) {
            var DTO = { 'pageLevelImageError': _myPage };
        
            $.getScript("/scripts/json.js", function() {
                $.ajax({ type: "POST",
                    url: "/pff_webservice.asmx/BrokenImage",
                    data: JSON.stringify(DTO),
                    contentType: "application/json; charset=utf-8",
                    dataType: "json"                    
                });
            });
        }            
    }
}

function InitializeWaterMark() {
    var $ts = $("#txtSearch");
    var swapValues = $ts.val();
    $ts.focus(function() {
        if ($(this).val() == swapValues) {
            $(this).val("");
            $(this).css("color", "#000");
        }
    }).blur(function() {
        if ($.trim($(this).val()) == "") {
            $(this).val(swapValues);
            $(this).css("color", "#999");
        }
    });

}

function addMega() {//master    
    $("#" + this.id + " .navName").css("z-index",12);
    $("#" + this.id + " .linksWrapper").css("z-index",11);
    $("#" + this.id + " .navName").fadeIn(200);
    $("#" + this.id + " .linksWrapper").fadeIn(200); 
}

function removeMega() {//master
    $("#" + this.id + " .navName").fadeOut(100);
    $("#" + this.id + " .linksWrapper").fadeOut(100);
    $("#" + this.id + " .navName").css("z-index",10);
    $("#" + this.id + " .linksWrapper").css("z-index",9); 
}

function navChange(navId) //customercare and myaccount
{ 
    $(navId).attr("class","selected");	 
}






