window.onload = function(){
	/*ROUND THE TOP OF THE SLIDER */
      var settings1 = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 0 },
          br: { radius: 0 },
          antiAlias: true,
          autoPad: false,
          validTags: ["div"]
      };

      var myBoxObject1 = new curvyCorners(settings1, "printSols");
      myBoxObject1.applyCornersToAll();
      
/*ROUND THE BOTTOM OF THE SLIDER */
      var settings2 = {
          tl: { radius: 1 },
          tr: { radius: 1 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: false,
          validTags: ["div"]
      };

      var myBoxObject2 = new curvyCorners(settings2, "prodInfo");
      myBoxObject2.applyCornersToAll();

/*ROUND THE CALCULATOR */
      var settings3 = {
          tl: { radius: 10 },
          tr: { radius: 10 },
          bl: { radius: 10 },
          br: { radius: 10 },
          antiAlias: true,
          autoPad: false,
          validTags: ["div"]
      };

      var myBoxObject3 = new curvyCorners(settings3, "labelCalc");
      myBoxObject3.applyCornersToAll();

	 $("printsol_drop")[0].selected = true;
}
var firstClick = false;      
var currentImage = 0;
var imgInfos=new Array();
var imgHeaders=new Array();
var imgIds=new Array()
var imgImages=new Array()
var imgMouseovers=new Array();
var img2Ctr=0;
var totalImages;
var wait = 0;
var loadingImageSrc = "/img/sliderLoad.png";

//important, this is the width of the images used for scrolling
var imgSize = 342;

function loadRestSlider(){
      for(var i =1; i<imgImages.length; i++)
      	jQuery("#"+imgIds[i]).attr("src","/img/sliderImages/"+imgImages[i]);
      
      for(var i =1; i<imgMouseovers.length; i++)
      	jQuery("<img>").attr("src","/img/sliderImages/"+imgMouseovers[i]);
}
function printsolDropChange(){
	var currentSelected = $("printsol_drop")[$("printsol_drop").selectedIndex].value;
	currentImage = parseInt(currentSelected);
	$("stuff").style.left = $("printsol_drop")[$("printsol_drop").selectedIndex].value *-imgSize +"px";
	$("infoHeaderBlock").innerHTML = imgHeaders[currentImage];
	$("infoDescrBlock").innerHTML = imgInfos[currentImage];
	//Load the image you picked
	  if(jQuery("#"+imgIds[currentImage]).attr("src") == loadingImageSrc)
		jQuery("#"+imgIds[currentImage]).attr("src","/img/sliderImages/"+imgImages[currentImage]);
}

jQuery.noConflict();

jQuery(document).ready(function(){

		new YAHOO.Hack.FixIESelectWidth("printsol_drop");
		

				
        new Ajax.Request('/php/getSliderInfo.php',
          {method:'get',
            onSuccess: function(payload){
                var json = payload.responseText.evalJSON();
                //set the number of images based on the number of items in the slider table
                totalImages = json.slider_info.length;
                //loop through the info and set the infos and headers arrays
                for(var i=0;i<json.slider_info.length;i++){
					imgInfos[i] = json.slider_info[i].info;
					imgHeaders[i]= json.slider_info[i].title+":";
					imgIds[i]=json.slider_info[i].mainImageId;
					imgImages[i]=json.slider_info[i].mainImage1;
					if(json.slider_info[i].mainImage2 !=null){
						imgMouseovers[img2Ctr]=json.slider_info[i].mainImage2;
						img2Ctr++;
					}
					
                }
                
				/*INITIALIZE THE INFO FOR THE 1st IMAGE */     
				$("infoHeaderBlock").innerHTML = imgHeaders[0];
				$("infoDescrBlock").innerHTML = imgInfos[0];
				jQuery("#"+imgIds[0]).attr("src","/img/sliderImages/"+imgImages[0]);

				//jQuery.preloadImages("/img/sliderImages/"+imgImages[0]);
				
		jQuery("div.middle").mouseover(function(){
		jQuery("a.next").css("visibility","visible");
		jQuery("a.prev").css("visibility","visible");
		})
		
		jQuery("div.middle").mouseout(function(){
		jQuery("a.prev").css("visibility","hidden");
		jQuery("a.next").css("visibility","hidden");
		})
          },
            onFailure: function(){ 
            alert('Failed to get Slider Descriptions...')
          }
          });
	loadRestSlider();
	//get image ready for submit overlay
	jQuery.preloadImages(
	"/img/aboutus2.png"
	,"/img/checkorders.png"
	,"/img/contact.png"
	,"/img/viewcart.png"
	,"/img/orderonline.png"
	,"/img/labels.png"
	,"/img/overlays.png"
	,"/img/business.png"
	,"/img/tags.png"
	,"/img/graphicart.png"
	,"/img/leftarrow.png"
	,"/img/sliderButtons/requestaquote.png"
	,"/img/sliderButtons/requestaquote.png"
	,"/img/sliderButtons/readytoship.png"
	,"/img/sliderButtons/requestaquote.png"
	,"/img/sliderButtons/moreinfo.png"
	,"/img/sliderButtons/moreinfo.png"
	,"/img/sliderButtons/moreinfo.png"
	,"/img/sliderButtons/requestaquote.png"
	,"/img/sliderButtons/readytoship.png"
	,"/img/sliderButtons/requestaquote.png"
	,"/img/sliderButtons/requestaquote.png"
	,"/img/rightarrow.png"
	,"/img/home.png"
	,"/img/shopsjl.png"
	,"/img/samples.png"
	,"/img/aboutus21.png"
	,"/img/checkorders1.png"
	,"/img/contact1.png"
	,"/img/viewcart1.png"
	,"/img/orderonline1.png"
	,"/img/labels1.png"
	,"/img/overlays1.png"
	,"/img/business1.png"
	,"/img/tags1.png"
	,"/img/graphicart1.png"
	,"/img/leftarrow1.png"
	,"/img/sliderButtons/requestaquote1.png"
	,"/img/sliderButtons/requestaquote1.png"
	,"/img/sliderButtons/readytoship1.png"
	,"/img/sliderButtons/requestaquote1.png"
	,"/img/sliderButtons/moreinfo1.png"
	,"/img/sliderButtons/moreinfo1.png"
	,"/img/sliderButtons/moreinfo1.png"
	,"/img/sliderButtons/requestaquote1.png"
	,"/img/sliderButtons/readytoship1.png"
	,"/img/sliderButtons/requestaquote1.png"
	,"/img/sliderButtons/requestaquote1.png"
	,"/img/rightarrow1.png"
	,"/img/home1.png"
	,"/img/shopsjl1.png"
	,"/img/samples1.png"
	)
});

        
 
    
    function moveToPrevious()
    {
    
    //load all the slider images on first left or right click
    if(!firstClick){
    	firstClick=true;
		jQuery(".sjlabelSliderImage").each(function(){
		  var imageNumber = jQuery(this).attr("id");
		  imageNumber = imageNumber.replace(/slider/,"");
		  imageNumber = parseInt(imageNumber)-1;
		 jQuery(this).attr("src","/img/sliderImages/"+imgImages[imageNumber]);
		});
    }
    if(currentImage > 0 && wait == 0)
    {
    wait = 1;
    imgHeaders[currentImage]
    new Effect.Move('stuff', { x: imgSize, y: 0, duration:0.5, transition: Effect.Transitions.sinoidal,queue:'end', 
    afterFinish: function() { 
                              currentImage--;
                              //Load the previous image
                              if(jQuery("#"+imgIds[currentImage]).attr("src") == loadingImageSrc)
                              	jQuery("#"+imgIds[currentImage]).attr("src","/img/sliderImages/"+imgImages[currentImage]);
                              
                              $("infoHeaderBlock").innerHTML = imgHeaders[currentImage];
                              $("infoDescrBlock").innerHTML = imgInfos[currentImage];
                              $("printsol_drop").selectedIndex = currentImage;
                              wait = 0;
                            }
                                });

} //otherwise your on the first image so clicking again goes to the last image
    else if(currentImage ==0 && wait==0){
        wait = 1;
    new Effect.Move('stuff', { x: -imgSize*(totalImages-1), y: 0, duration:0.5, transition: Effect.Transitions.sinoidal,queue:'end', 
    afterFinish: function() { 
                              currentImage=(totalImages-1);
                              //Load the last image
                              if(jQuery("#"+imgIds[currentImage]).attr("src") == loadingImageSrc)
                              	jQuery("#"+imgIds[currentImage]).attr("src","/img/sliderImages/"+imgImages[currentImage]);
                              
                              $("infoHeaderBlock").innerHTML = imgHeaders[currentImage];
                              $("infoDescrBlock").innerHTML = imgInfos[currentImage];
                              $("printsol_drop").selectedIndex = currentImage;
                              wait = 0;
                            }
                                });
    }
    }

    function moveToNext()
    {
    //load all the slider images on first left or right click
    if(!firstClick){
    	firstClick=true;
		jQuery(".sjlabelSliderImage").each(function(){
		  var imageNumber = jQuery(this).attr("id");
		  imageNumber = imageNumber.replace(/slider/,"");
		  imageNumber = parseInt(imageNumber)-1;
		 jQuery(this).attr("src","/img/sliderImages/"+imgImages[imageNumber]);
		});
    }
    if(currentImage <totalImages-1 && wait == 0)
    {
    wait = 1;
    new Effect.Move('stuff', { x: -imgSize, y: 0, duration:0.5, transition: Effect.Transitions.sinoidal,queue:'end', 
    afterFinish: function() { 
                              currentImage++;
                              //Load the next image
                              if(jQuery("#"+imgIds[currentImage]).attr("src") == loadingImageSrc)
                              	jQuery("#"+imgIds[currentImage]).attr("src","/img/sliderImages/"+imgImages[currentImage]);
                              
                              $("infoHeaderBlock").innerHTML = imgHeaders[currentImage];
                              $("infoDescrBlock").innerHTML = imgInfos[currentImage];
                              $("printsol_drop").selectedIndex = currentImage;
                              wait = 0;
                            }
                                });

    } //otherwise your on the last image so clicking again goes to the first image
    else if(currentImage ==(totalImages-1) && wait==0){
        wait = 1;
    new Effect.Move('stuff', { x: imgSize*(totalImages-1), y: 0, duration:0.5, transition: Effect.Transitions.sinoidal,queue:'end', 
    afterFinish: function() { 
                              currentImage=0;
                              //Load the first image
                              if(jQuery("#"+imgIds[currentImage]).attr("src") == loadingImageSrc)
                              	jQuery("#"+imgIds[currentImage]).attr("src","/img/sliderImages/"+imgImages[currentImage]);
                              
                              $("infoHeaderBlock").innerHTML = imgHeaders[currentImage];
                              $("infoDescrBlock").innerHTML = imgInfos[currentImage];
                              $("printsol_drop").selectedIndex = currentImage;
                              wait = 0;
                            }
                                });
    }
    }

jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}
