﻿/*
 * PagerAjax 1.0 - PagingAjax
 * By Cody Lindley (http://www.codylindley.com)
 * Copyright (c) 2006 Everett Creekmore
 * Licensed under the MIT License:
 *   http://www.opensource.org/licenses/mit-license.php
 * PagerAjax is built on top of the very light weight jQuery library.
 */

  
    //on page load call TB_init
    $(document).ready(start_init_scripts);
    //jQuery(document).ready(product_page());
    
    $(document).ready(function(){
	//Fix IE control activation
	if (navigator.appName == "Microsoft Internet Explorer") {
		$('object, embed, applet').each(function() {
			this.outerHTML = this.outerHTML;
		    });
	    }
    });
    
/*FLY OUT MENU CONTROL*/   
$(document).ready(function(){
			$("#flynav-one li").hover(
				function(){ $("ul", this).fadeIn("fast"); }, 
				function() { } 
			);
	  	if (document.all) {
				$("#flynav-one li").hoverClass ("sfHover");
			}
	  });
	  
		$.fn.hoverClass = function(c) {
			return this.each(function(){
				$(this).hover( 
					function() { $(this).addClass(c);  },
					function() { $(this).removeClass(c); }
				);
			});
		};	  
/*END FLY OUT MENU CONTROL*/

/*FLY OUT MENU CONTROL*/   
$(document).ready(function(){
			$("#Dealernav-one li").hover(
				function(){ $("ul", this).fadeIn("fast"); }, 
				function() { } 
			);
	  	if (document.all) {
				$("#Dealernav-one li").hoverClass ("sfHover");
			}
	  });
	  
		$.fn.hoverClass = function(c) {
			return this.each(function(){
				$(this).hover( 
					function() { $(this).addClass(c);  },
					function() { $(this).removeClass(c); }
				);
			});
		};	  
/*END FLY OUT MENU CONTROL*/      



var currentSectionActive = null;
var displayState = Get_Cookie('sdgdisplayState');
var currentActivePage = null;
var currentPathName = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);


//alert(displayState);
if(displayState == null)
{
   displayState = 'slides';
}


    var iCount = 0;
    var iPagerCount = 0;
    //add thickbox to href elements that have a class of .thickbox
    pager_init =  function(){
	    
	            $("a.PageNumber").click(function(){
	            getPageWithPagingSupport(this.href + '&ascx=empty&XmlPackage=sdg.ArtistProductGrid.xml.config',"div#SubSection");
	            return false;
	            });
	            
	           
	        }
	        
	pagerAddToNumbers =  function(){
	            $("a.PageNumber").click(function(){
	                getPageWithPagingSupport(this.href + '&ascx=empty&XmlPackage=sdg.sectiongrid.xml.config',"div#thumbs");
	                return false;
	            });
	            
	           
	        }
    
    product_page =  function(){
	    
	            //alert('run');
	            $("a.ProductLink").click(function(){
	            getPage(this.href + '&ascx=empty',"div#SubSection");
	            return false;
	            });
	       }
	       
   
    
    sectionLinksRowSwitch = function()
        {
            $(".stripeMe tr").click(function() {$(".stripeMe tr").removeClass("over");$(".stripeMe tr").removeClass("clk");$(this).addClass("clk");});
        }
    
    
    
    //set the var
   
    
    function setRowColorForSection(onState)
    {
        
        
        $("div#dv" + currentSectionActive).removeClass("sectionActive");
        currentSectionActive = onState;
        $("div#dv" + currentSectionActive).addClass("sectionActive");
        //alert(currentSectionActive);
    }
    
    
    
    function sectionslinks_init(){
	    //alert('sectionslinks_init-called');
	    $("a.SectionLinks").click(function(){
	            //This is where we need to set the cookie
	            Set_Cookie("FirstLoad" + currentPathName,this.id,1,'hours');
	            getPage(this.href + '?ascx=empty&XmlPackage=sdg.entityslideshowViewer.xml.config&issub=yes',"div#SlideShow");
	            setRowColorForSection(this.id);
	            $("span#" + displayState + "Link").addClass("sectionActive");
	            return false;
	    });
	    
	    $("a.SectionLinksDesc").click(function(){
	            //getPageWithPagingSupport(this.href + '?ascx=empty&XmlPackage=sdg.ArtistProductGrid.xml.config',"div#SubSection");
	            
	            getPage(this.href + '?ascx=empty',"div#SlideShow");
	            setRowColorForSection(this.id);
	            $("span#" + displayState + "Link").removeClass("sectionActive");
	            return false;
	    });

	    
	    
    }
    
    function startUpDisplay()
    {
      //alert(displayState);
      
      if(displayState == "slides")
        {
            $("div#thumbs").fadeOut("fast");
            $("div#slides").fadeIn("slow");
            $("span#slidesLink").addClass("sectionActive");
            document.getElementById("slides").style.visibility = "visible";
            //slides.style.visibility="visible";
        }
        
        if(displayState == "thumbs")
        {
            $("div#slides").fadeOut("fast");
            $("div#thumbs").fadeIn("slow");
            $("span#thumbsLink").addClass("sectionActive");
            document.getElementById("thumbs").style.visibility = "visible";
           //thumbs.style.visibility="visible";
        }
     
    }
    
    function changeDisplay(sDisplayType)
    {

       if(sDisplayType != displayState)
       {
           //Turn off the current displayState
           $("span#" + displayState + "Link").removeClass("sectionActive");
           
           //Turn on the new displayState
           $("span#" + sDisplayType + "Link").addClass("sectionActive");
           
           //set the new displayState
           displayState = sDisplayType;
           
           //set the cookie
           Set_Cookie('sdgdisplayState',sDisplayType,60)

           //load the new page
           getPage(currentActivePage,"div#SlideShow");
             
       }

       
    }
    
    function productImageDropShadow()
    {
	    //alert('hhh');
	    $("img.ProductImages").wrap("<div class='wrap1'><div class='wrap2'>" + "<div class='wrap3'></div></div></div>");
    }
    
    function getPageWithPagingSupport(url,el,firstLoad)
    {

                $(el).toggle();
                $(el).load(url,
                function(){
                    //pager_init(),
                    $(el).fadeIn("slow");
                   });
           
        

    }
    
    function getPreLoadPageWithPagingSupport(url,el)
    {
        
           currentActivePage = url;
                 
           $(el).load(url + '&display=' + displayState,
            function(){
                $(el).fadeIn("slow");
               });
        
      
    }


    
     function getPage(url,el)
    {
         
            currentActivePage = url;
                        
            //$(el).fadeOut("slow");
            $(el).toggle();
            $(el).load(url + '&display=' + displayState,
            function(){
                $(el).fadeIn("slow");
               });
        
        //$("div#cont").hide("fast");
        //$("div#cont").load(url,function(){pager_init;});
    }
    
    function getFastPage(url,el)
    {
         
            $(el).fadeOut("fast");
            $(el).load(url,
            function(){
                $(el).fadeIn("fast");
               });
        
        //$("div#cont").hide("fast");
        //$("div#cont").load(url,function(){pager_init;});
    }
    
  
    
    
    
    function start_init_scripts()
    {
        //alert(iCount);
        //alert('start_init_scripts-run');
        //pager_init();
        if(iCount == 0)
        {
            sectionslinks_init();
           
            
        }
        //TB_init();
        iCount = iCount + 1;
    }
    



