var sku_im='';
var size_im='';
var poz=1;
function sh_im(im,sku,style,thumb_patch,image_patch)
{
		sku_im=sku;
		size_im=image_patch;
		var poz=1;

 var arrIndexes = new Array;
 var objSel = document.getElementById("st_size");

  for (var i=0; i < objSel.options.length; i++)
  {
      if (objSel.options[i].selected)
	  {
		arrIndexes.push(i);
		var cur_s=objSel.options[arrIndexes].value;
	  }
  }

	if(image_patch!=cur_s)
	{
	UpdatePreview('../zoom_and_rotate/get_styles.php?size='+image_patch+'&act=update&sku='+sku+'&style='+style+'');
	
	 var arrIndexes = new Array;

 		 for (var i=0; i < objSel.options.length; i++)
 		 {
      		if (!objSel.options[i].selected)
	  		{
				arrIndexes.push(i);
	  		}
  		}
	objSel.options[arrIndexes].selected=true;
	}

	 document.getElementById('image').src='http://gotvape.com/images/'+image_patch+'/'+im;
	 document.getElementById('image').style.width='450px';
	 document.getElementById('image').style.left='0px';
	 document.getElementById('image').style.top='0px';
	 UpdatePreview('../zoom_and_rotate/get_images.php?size='+image_patch+'&style='+style+'&sku='+sku);
	 product_zoom= new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
	 
window.setTimeout('update_st_col("'+sku+'","'+style+'")',3);
$('sku').value=sku;


var param=explode('-',sku);

$('Product_Code').value=param[0];
$('AttributeValue[1]').value=param[1];
$('AttributeValue[2]').value=param[2];

//alert('AttributeValue[1]'+$('AttributeValue[1]').value);
//alert('AttributeValue[2]'+$('AttributeValue[2]').value);


if(document.getElementById(sku))
{
document.getElementById(sku).className='image-img-box_red';
document.getElementById(cur_sel).className='image-img-box';
cur_sel=sku;
}
}
function update_st_col(sku,style)
{
 var arrIndexes = new Array;
 var objSel = document.getElementById("st_style");
  for (var i=0; i < objSel.options.length; i++)
  {
      if (objSel.options[i].value==''+sku+'|'+style+'')
	  {
		arrIndexes.push(i);
		objSel.options[arrIndexes].selected=true;
	  }
  }
  /*	alert(document.getElementById("st_scolor").name)

   var arrIndexes = new Array;
 var objSel2 = document.getElementById("st_scolor");

  for (var i=0; i < objSel2.options.length; i++)
  {
      if (objSel2.options[i].value==''+sku+'|'+style+'')
	  {
		arrIndexes.push(i);
		objSel2.options[arrIndexes].selected="selected";
	  }
  }

	*/
}

function objSt_style(val1,val2,val3)
{
var name=explode('|',val1);
var im=name[0]+'-pos1.jpg';
var sku=name[0];
var style=name[1];
sh_im(im,sku,style,val2,val3);
}
	function sh_ang(im)
	{
	 document.getElementById('image').src=im;
	 document.getElementById('image').style.width='450px';
	 document.getElementById('image').style.left='0px';
	 document.getElementById('image').style.top='0px';
	 product_zoom= new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
	}

	function rotate(pozition)
	{
		if(pozition=='left')
		{ 
			if(poz>2)
			{
				poz=poz-1;
			}
		}else if(pozition=='right')
		{
			if(poz<8)
			{
				poz=poz+1;
			}
		}
		if(file_exists('../images/'+size_im+'/'+sku_im+'-pos'+poz+'.jpg'))
		{
			document.getElementById('image').src='http://gotvape.com/images/'+size_im+'/'+sku_im+'-pos'+poz+'.jpg';
	 		document.getElementById('image').style.width='450px';
	 		document.getElementById('image').style.left='0px';
	 		document.getElementById('image').style.top='0px';
	 		product_zoom= new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');

		}
		else
		{
			
			
		}
		
}

function ShangeBySize(value)
{
UpdatePreview('get_styles.php?size='+value+'&act=size');

document.getElementById('image').style.width='450px';
document.getElementById('image').style.left='0px';
document.getElementById('image').style.top='0px';

product_zoom= new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
}

function UpdatePreview(url){
 new Ajax.Request(url, {  
             method:'get',  
             onSuccess: function(transport){ 
               eval(transport.responseText);  
             }  
           })  
}

function file_exists (url) {
    
    var req = window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP") : new XMLHttpRequest();
    if (!req) throw new Error('XMLHttpRequest not supported');
      
    // HEAD Results are usually shorter (faster) than GET
    req.open('HEAD', url, false);
    req.send(null);
    if (req.status == 200){
        return true;
    }
    
    return false;
}
function explode( delimiter, string, limit ) {
 
    var emptyArray = { 0: '' };
    
    // third argument is not required
    if ( arguments.length < 2 ||
        typeof arguments[0] == 'undefined' ||
        typeof arguments[1] == 'undefined' )
    {
        return null;
    }
 
    if ( delimiter === '' ||
        delimiter === false ||
        delimiter === null )
    {
        return false;
    }
 
    if ( typeof delimiter == 'function' ||
        typeof delimiter == 'object' ||
        typeof string == 'function' ||
        typeof string == 'object' )
    {
        return emptyArray;
    }
 
    if ( delimiter === true ) {
        delimiter = '1';
    }
    
    if (!limit) {
        return string.toString().split(delimiter.toString());
    } else {
        // support for limit argument
        var splitted = string.toString().split(delimiter.toString());
        var partA = splitted.splice(0, limit - 1);
        var partB = splitted.join(delimiter.toString());
        partA.push(partB);
        return partA;
    }
}

function addOption (oListbox, text, value, isDefaultSelected, isSelected)
{
  var oOption = document.createElement("option");
  oOption.appendChild(document.createTextNode(text));
  oOption.setAttribute("value", value);

  if (isDefaultSelected) oOption.defaultSelected = true;
  else if (isSelected) oOption.selected = true;

  oListbox.appendChild(oOption);
}
function sh_av_col(id)
{
	
window.setTimeout('update_c_style('+id+')',800);
}
function update_c_style(id)
{
	document.getElementById(id).bgColor="#CCCCCC";
	if(document.getElementById(col_cur))
	{
	document.getElementById(col_cur).bgColor="";
	}
col_cur=id;
}

function init()
{
  product_zoom = new Product.Zoom('image', 'track', 'handle', 'zoom_in', 'zoom_out', 'track_hint');
   

   
car= new UI.Carousel($("horizontal_carousel"), {
					   'container':'.container_carusel',
					   'previousButton': '.previous_button', 
                        'nextButton': '.next_button',
						'disabledButtonSuffix' : '_disabled'});

car2=new UI.Carousel($("horizontal_carousel_angle"), {
					   'container':'.container_carusel_angle',
					   'previousButton': '.previous_button', 
                        'nextButton': '.next_button',
						'disabledButtonSuffix' : '_disabled'});

car3=new UI.Carousel($("horizontal_carousel_smal"), {
					   'container':'.container_carusel_smal',
					   'previousButton': '.previous_button', 
                        'nextButton': '.next_button',
						'disabledButtonSuffix' : '_disabled'});
    //  document.observe('carousel:scroll:ended', function(event) {
     //  alert("Carousel with id " + event.memo.carousel.id + " has just been scrolled");
     //  });

var param=explode('-',sku_im);

$('Product_Code').value=param[0];
$('AttributeValue[1]').value=param[1];
$('AttributeValue[2]').value=param[2];


}
 Event.observe(window, "load", init);
//window.addEvent('domready', init);




