﻿// Darong Ma June 04 2009 Pentax Navigation
function imgOver(which)
{
var src=which.find("img").attr("src");
src=src.replace("default","over");
which.find("img").attr("src",src);
}
function imgOut(which)
{
var src=which.find("img").attr("src");
src=src.replace("over","default");
which.find("img").attr("src",src);
}

var MainNav=new Array();
MainNav[0]="categories.aspx;product.aspx;slr;digital-camera;camera-lenses;accessories".split(";");
MainNav[1]="about-us.aspx;/about/".split(";");
MainNav[2]="support.aspx;/support/".split(";");
MainNav[3]="wheretobuy.aspx;/wheretobuy".split(";");

function getPageSection(url)
{
    for(var i=0;i<MainNav.length;i++)
    {
        for(var c=0;c<MainNav[i].length;c++)
        {
            if(url.indexOf(MainNav[i][c])!=-1)return i;
        }
    }
    return -1;
}

/*Top Navigation Initialization*/
$(document).ready
(
    function()
    {
        //Main Nav Item
        $(".g-nav-item").hover
        (
            function()
            {
                imgOver($(this));
                var index=$(".g-nav-item").index(this);
                $(".g-subnav").hide().eq(index).show();
            },
            function()
            {
                if($(this).attr("rel")=="1")return;
                imgOut($(this));
                
                var index=$(".g-nav-item").index(this);
                $(".g-subnav").eq(index).hide();
            }
        );
        $(".g-nav-logo").hover(function(){$(".g-subnav").hide();},function(){});
        //SubNav
        //$(".g-subnav .g-subnav-item:last").css("border-bottom","none");
        $(".g-subnav").hover
        (
            function()
            {
                
            }
            ,
            function()
            {
                $(this).hide();
            }
        );
        //SubNav Item
        $(".g-subnav-item").hover
        (
            function()
            {
                $(this).css("background-color","#b60000");
                $(this).find("a").css("color","#ffffff");  
            },
            function()
            {
                $(this).css("background-color","#ffffff");
                $(this).find("a").css("color","#333333");  
            }
        ).click
        (
            function()
            {
                 if($(this).find("a").attr("target")!="_blank")top.location=$(this).find("a").attr("href");
            }
        );
        
        //Page Belong To Which Section
        var pageurl=top.location.href;
        var PSIndex=getPageSection(pageurl);
        if(PSIndex!=-1)
        {
            $(".g-nav-item").eq(PSIndex).attr("rel","1");
            imgOver($(".g-nav-item").eq(PSIndex));
        }
         
        
        
        /*Bottom Module Initialization*/
        if(document.getElementById("HomepageModules")!=null)
        {
            $("#HomepageModules").find("div").css("padding-right","0px");
            $("#PromotionsModule,#PENTAXStoreModule,#InterestingThingsModule").css("margin-right","18px");
            
        }
    }
);

