jQuery(InitSite);
var stoptimer=0;

function InitSite()
{
    $("#nav .item img").hover(
        function() {this.src=this.src.replace("_off","_on");},  
        function() {this.src=this.src.replace("_on","_off");}
    );
    
    if($("#whatsnewslider").size())
    {
        $('#whatsnewslider').css("width",($('#sliderchanger div').size()*900)+"px");
        $('#sliderchanger :first').addClass("enabled");
        $('#sliderchanger div').bind("click",
            function(e)
            {
                stoptimer=1;
                Scroll(e.target.id.substring(7));
            }
        );
        
        $.timer(5000,
            function(timer)
            {
                if(stoptimer)
                    timer.stop();
                else
                {
                    var current=parseInt($('#sliderchanger .enabled').attr("id").substring(7));
                    if(current!=($('#sliderchanger div').size()-1))
                        Scroll(current+1);
                    else
                        Scroll(0);
                }
            }
        );
    }
}

function Scroll(number)
{
    $('#sliderchanger div').removeClass("enabled");
    $('#whatsnewslider_container').scrollTo((number*900),{axis: 'x', duration: 250});    
    $('#section'+number).addClass("enabled");    
}

$(document).ready(function() 
{
   // By suppling no content attribute, the library uses each elements title attribute by default
   $('#page_body_right-productview a[href][title].tiptool').qtip({
      content: {
         text: false // Use each elements title attribute
      },
	  show: 'mouseover',
	  hide: 'mouseout',
	  style: {
	  color:'#000000',
	  background: '#EEE9E8', 
      	 	 border: {
	         width: 2,
	         radius: 8,
			 color: '#736059'

      		},
      width: 400,
	  
	  tip:'rightMiddle'
	  
},	  
position: {
	      corner: {
	         target: 'leftMiddle',
	         tooltip: 'rightMiddle'
	      }
   		}
   });
   
   // NOTE: You can even omit all options and simply replace the regular title tooltips like so:
   // $('#content a[href]').qtip();
});

var siteurl='http://www.chantillyrose.co.uk/';	

function email(str) {
	    var error = "";
  var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){  
		document.getElementById("email").style.backgroundColor = '#FFDFE3';	
		
		   error = "Invalid E-mail\n";
		   return error;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){  
	document.getElementById("email").style.backgroundColor = '#FFDFE3';	
		
		   error = "Invalid E-mail\n";
		   return error;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	document.getElementById("email").style.backgroundColor = '#FFDFE3';	
		
		       error = "Invalid E-mail\n";
		   return error;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		document.getElementById("email").style.backgroundColor = '#FFDFE3';
		
		     error = "Invalid E-mail\n";
		   return error;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){	 
	document.getElementById("email").style.backgroundColor = '#FFDFE3';
	
		      error = "Invalid E-mail\n";
		   return error;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){	
		document.getElementById("email").style.backgroundColor = '#FFDFE3';
		
		   error = "Invalid E-mail\n";
		   return error;
		 }
		
		 if (str.indexOf(" ")!=-1){
		     error = "Invalid E-mail\n";
		document.getElementById("email").style.backgroundColor = '#FFDFE3';
		   return error;
		 }

		   return error; 
}
 

function fetchinfo (str,div)
 	{
		document.getElementById(div).style.display = 'block';
		  
		$("#"+div).load(siteurl+str,{async: true});	
}

 function dochange(str,prodid)
{  	   
	$("#selectsize").load(siteurl+"prt.grabsizes.php?type="+str+"&prodid="+prodid,{async: true});	
    $("#productthumbnails").load(siteurl+"prt.changethumb.php?type="+str+"&prodid="+prodid,{async: true});	
	$("#productimage").load(siteurl+"prt.changemainpic.php?type="+str+"&prodid="+prodid,{async: true});	
	 
	//$("#"+"altcontainer").get(siteurl+"prt.changealt.php?type="+str+"&prodid="+prodid,{async: true}); 

} 
 function dosetchange(str,prodid)
{  	   
	$("#selectsizeaa").load(siteurl+"prt.grabsetsizes.php?type="+str+"&prodid="+prodid,{async: true});	
   // $("#productthumbnails").load(siteurl+"prt.changethumb.php?type="+str+"&prodid="+prodid,{async: true});	
	//$("#productimage").load(siteurl+"prt.changemainpic.php?type="+str+"&prodid="+prodid,{async: true});	
	 
	//$("#"+"altcontainer").get(siteurl+"prt.changealt.php?type="+str+"&prodid="+prodid,{async: true}); 

}
function closediv(div){

   document.getElementById(div).style.display = 'none';

   }

function getsizes(str)
    { 
	 var url=siteurl+'prt.grabsizes.php';	   
		 url=url+"?type="+str;	 
		
	   $("#selectsize").load(siteurl+url,{async: true});	
    }
function getqty(str)
    { 
	 var url=siteurl+'prt.grabstock.php?type='+str;	   
    $("#qty").load(url,{async: true});
	$("#"+"price").load(siteurl+"prt.changeprice.php?type="+str,{async: true});	

    }
 function getqtyaa(str)
    { 
	 var url=siteurl+'prt.grabstock.php?aa=aa&type='+str;	   
    $("#qtyaa").load(url,{async: true});
	$("#"+"priceaa").load(siteurl+"prt.changesetprice.php?aa=aa&type="+str,{async: true});	

    }
function validate_product() {
var reason = "";

  	reason += validatechoice();
  	reason += validatesize();
	reason += validateqty();

  
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
else
{  
   document.addtobasket.action=siteurl+'cartcontrol/';
   document.addtobasket.submit();
   }
}

function validate_productset() {
var reason = "";

  	reason += validatechoice();
  	reason += validatesize();
	reason += validateqty();
	reason += validatesizeaa();
  	reason += validateqtyaa();
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }
else
{  
   document.addtobasket.action=siteurl+'cartcontrol/';
   document.addtobasket.submit();
   }
}

function validatechoice() {
    var error = "";
 
    if (document.addtobasket.ppid.value == "-1" || document.addtobasket.ppid.value == "") 
	{	
		document.getElementById("ppid").style.backgroundColor = '#FFDFE3';
        error = "Please select your colour choice.\n";
    } 
    return error;  
}
function validatesize() {
    var error = "";
 
    if (document.addtobasket.typea.value == "-1" || document.addtobasket.typea.value == "") 
	{  
		document.getElementById("typea").style.backgroundColor = '#FFDFE3';
        error = "Please select your size.\n";
    } 
    return error;  
}
function validateqty() {
    var error = "";
 
    if (document.addtobasket.quantity.value == "-1" || document.addtobasket.quantity.value == "") 
	{  
		document.getElementById("quantity").style.backgroundColor = '#FFDFE3';
        error = "Please select quantity required.\n";
    } 
    return error;  
}
function validatesizeaa() {
    var error = "";
 
    if (document.addtobasket.typeaa.value == "-1" || document.addtobasket.typeaa.value == "") 
	{  
		document.getElementById("typeaa").style.backgroundColor = '#FFDFE3';
        error = "Please select your matching item size.\n";
    } 
    return error;  
}
function validateqtyaa() {
    var error = "";
 
    if (document.addtobasket.quantityaa.value == "-1" || document.addtobasket.quantityaa.value == "") 
	{  
		document.getElementById("quantityaa").style.backgroundColor = '#FFDFE3';
        error = "Please select your matching item quantity required.\n";
    } 
    return error;  
}
