// starting the script on page load
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});
$(document).ready(function(){
						
screenshotPreview();
	fadeInVineYardImage();
});
function fadeInVineYardImage(){
	$("#vineYardImg").hide();
	
	$.ajax({
    type: "GET",
    url: "includes/vineyardData.xml",
    dataType: "xml",
    success: parseXml
  });	
$("#vineYardImg").fadeIn(2300);
}
function parseXml(xml)
{
  var vinyardImages= new Array();
 $(xml).find("vineYardItem").each(function()
  {
    vinyardImages.push($(this).find("Image").text()); 
  }
  );
vinyardImages.sort(function() {return 0.5 - Math.random()});
document.getElementById("vineYardImg").src=vinyardImages[0];
}

this.screenshotPreview = function(){	
	/* CONFIG */
		xOffset = 1;
		yOffset = -247;
		
if(detectIE()==8){
		xOffset = 1;
		yOffset = -258;
}
if(detectIE()==7){
		xOffset = 1;
		yOffset = -135;
}
if(detectIE()==6){
		xOffset = 1;
		yOffset = -135;
}

		//yOffset = 0;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result
		
	/* END CONFIG */
	$("a.screenshot").hover(function(e){
		$("body").append("<p id='screenshotA'><img src='images/bottles/"+ this.rel +"A.png' alt='' border='0' width='66' height='136' /></p>");
		$("body").append("<p id='screenshotB'><img src='images/bottles/"+ this.rel +"B.png' alt='' border='0' width='66' height='31' /></p>");
		YY=obtainPositionX(document.getElementById(this.id));
		XX=obtainPositionY(document.getElementById(this.id));
	if(!detectIE()){
		$("#screenshotA")
			.css("top",(XX + yOffset) + "px")
			.css("left",(YY + xOffset) + "px")
			.fadeIn("slow");
		$("#screenshotB")
			.css("top",(XX + yOffset+246) + "px")
			.css("left",(YY + xOffset) + "px")
			.fadeIn("slow");
		}
		else{
			$("#screenshotA")
			.css("top",(XX + yOffset) + "px")
			.css("left",(YY + xOffset) + "px")
			.show();
		$("#screenshotB")
			.css("top",(XX + yOffset+246) + "px")
			.css("left",(YY + xOffset) + "px")
			.show();
		}
			
	
		
				
		if(detectIE()==6 ){
				showPNGs();
				}
	 },
	function(){
		this.title = this.t;	
		$("#screenshotA").remove();
		$("#screenshotB").remove();
    });	
	
	
		
		
		
};
/*
.css("top",(e.pageY - xOffset) + "px")
			.css("left",(e.pageX + yOffset) + "px")*/
			


//Get X position
function obtainPositionX(elemento)
{
var x=0;
while(elemento.offsetParent)
{
x += elemento.offsetLeft;
elemento=elemento.offsetParent;
}
return x;
}

//Get Y position
function obtainPositionY(elemento)
{
var y=0;
while(elemento.offsetParent)
{
y += elemento.offsetTop;
elemento=elemento.offsetParent;
}
return y;
}
function detectIE(){
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
 var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
 if (ieversion>=8)
  return("8");
 else if (ieversion>=7)
 return("7");
 else if (ieversion>=6)
  return("6");
 else if (ieversion>=5)
  return("5");
}

}
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

