/**
 *  Rotate header image configurations.
 **/
var rotateImageDuration = 5000;
var headerImageFadeDuration = 2000;

$(document).ready(function()
{
    /**
     *  Rotate header images.
     **/
    if($("img", "#dvRotateImage").length > 0)
    {
        $("#dvRotateImage").find("img").css("opacity", 0).eq(0).css("opacity", 1);
        $(".jqSmallImage:first").attr("src", imagePath + "sqImgPink.gif");
        setInterval(rotateHeaderImage, rotateImageDuration);
    }
    
   
    $("#leftNav").accordion({
                                active:".jqLeftNavLinkActive",
                                autoheight: true,
                                selectedClass: 'jqLeftNavLinkActive'
                                ,event: "mouseover"
                            });
   
    //Blur event when click on subnav accordion
    $(".jqSubnavLink, .jqTopNavLinks").click(function()
    {
        $(this).blur();
    });
    //Redirect to artist products
    $(".leftSubNav").click(function()
    {
       window.location = $(this).attr("href");
       return false;
    });
    $(".leftSubNav").mouseover(function()
    {
       
       return false;
    });
    $("img").load()
    {
        setFooter();
    }
    
    
});
window.onresize = function()
{
	setFooter();
         var footer          = $("#dvContainer").offset();
         var footerLeft      = footer.left;
         $("#dvProductDetailsOverlay").css({left:footerLeft});
         $("#dvGalleryDetailsOverlay").css({left:footerLeft});
         
}
/**
* Method to rotate header images.
**/
function rotateHeaderImage()
{
    if(!this.currentImagePosition){
        this.currentImagePosition = 0;
    }
    
    if(!this.rotateImages){
        this.rotateImages = $("img", "#dvRotateImage");
    }
    
    if(!this.imageLength){
        this.imageLength = this.rotateImages.length;
    }
    
    this.nextImagePosition   = this.currentImagePosition + 1;
    if(this.nextImagePosition >= this.imageLength){
        this.nextImagePosition = 0;
    }
    
    if(this.currentImagePosition != this.nextImagePosition)
    {
        var fadeOutImage    = this.rotateImages.eq(this.currentImagePosition);
        var fadeInImage     = this.rotateImages.eq(this.nextImagePosition);
        
        if(fadeOutImage.length > 0 && fadeInImage.length > 0)
        {
            fadeOutImage.animate({"opacity" : 0}, headerImageFadeDuration);
            fadeInImage.animate({"opacity" : 1}, headerImageFadeDuration,   function()
                                                                            {
                                                                                if(!this.smallImages){
                                                                                    this.smallImages = $(".jqSmallImage");
                                                                                }
                                                                                this.smallImages.attr("src", imagePath + "sqImgGrey.gif").eq(nextImagePosition).attr("src", imagePath + "sqImgPink.gif");
                                                                            });
            this.currentImagePosition = this.nextImagePosition;
        }
    }
}
/**
* Method to get window height
**/
function getWindowHeight()
{
    var windowHeight = 0;
    if (typeof(window.innerHeight) == 'number')
    {
        windowHeight = window.innerHeight;
    }
    else
    {
        if (document.documentElement && document.documentElement.clientHeight)
        {
            windowHeight = document.documentElement.clientHeight;
        }
        else
        {
            if (document.body && document.body.clientHeight)
            {
            windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}
/**
* Method to get window width
**/
function getWindowWidth()
{
    var windowWidth = 0;
    if (typeof(window.innerWidth) == 'number')
    {
        windowWidth = window.innerWidth;
    }
    else
    {
        if (document.documentElement && document.documentElement.clientWidth)
        {
            windowWidth = document.documentElement.clientWidth;
        }
        else
        {
            if (document.body && document.body.clientWidth)
            {
            windowWidth = document.body.clientWidth;
            }
        }
    }
    return windowWidth;
}
/**
* Method to set footer
**/
function setFooter()
{
    if (document.getElementById)
    {
        var windowHeight = getWindowHeight();
       
        if (windowHeight > 0)
        {
            var bodyHeight = $(document).height();
            
            var footerHeight = $("#dvFooter").height();
            var contentHeight = bodyHeight - footerHeight;
            if(bodyHeight < windowHeight)
            {
                var top = (windowHeight - footerHeight) - 175;
                $("#dvFooter").css({position:"absolute", top: top});
            }
            
        }
    }


}
/**
* Method show or hide
* Ajax loader
**/
function ajaxLoader()
{
    if($("#dvAjaxLoader").is(":visible"))
    {
        $("#dvAjaxLoader").hide();
    }
    else
    {
        var windowHeight = getWindowHeight();
        var windowWidth = getWindowWidth();
        var scrollTop = (document.documentElement.scrollTop);
        
        if (windowHeight > 0)
        {
            //$("#dvAjaxLoader").css({top: (scrollTop + (windowHeight / 2)), left:((windowWidth/2)-100)});
            $("#dvAjaxLoader").css({top: (scrollTop + (2)), left:( windowWidth -100 )});
            $("#dvAjaxLoader").show();
        }
    }
}