
$(document).ready( function()
{
   rollover.init();
   
  var div = $('div.sc_menu'),
               ul = $('ul.sc_menu'),

               // unordered list's left margin
               ulPadding = 6;

  //Get menu width
  var divWidth = div.width();

  //Remove scrollbars


  //Find last image container
  var lastLi = ul.find('li:last-child');

 div.mouseenter(function(e){

	var x = e.pageX - this.offsetLeft;
	var y = e.pageY - this.offsetTop;
    var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
	//alert(e.pageX);
    var left = (x - div.offset().left) * (ulWidth-divWidth) / divWidth;
	div.animate({
		scrollLeft: left
	}, 300, "linear")
 	setTimeout(makemove, 300)
   });

div.mouseleave(function(){
	div.unbind("mousemove")
})

  //When user move mouse over menu
 makemove = function(){
	
	div.bind("mousemove", function(e){
    //As images are loaded ul width increases,
    //so we recalculate it each time
    var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;
	//alert(e.pageX);
    var left = (e.pageX - div.offset().left) * (ulWidth-divWidth) / divWidth;

    div.scrollLeft(left);
	})

}

addtocart = function(){ 
				//size = document.HTMLSelectElement('size').selectedIndex;
				id = $("#GID").val();
				size  = $("#size").val();
				alert(size);
				//size = document.getElementById('size').options[document.getElementById('size').selectedIndex]
				//chooser.options[chooser.selectedIndex].value;
				//size = document.getElementById('size').selectedIndex;
				
				link = 'cart.php?add='+id+'&s='+size;
				
				//var win = "width="+w+",height="+h+",menubar=no,location=no,resizable=yes,scrollbars=yes";
				newWin = window.open(link,'newWin',win);
}

$('#brandslink').click(function () {
	$('#brandspositioner').toggle("fast");
});


$('#sizeslink').click(function () {
	$('#sizespositioner').toggle("fast");
});
  
  	var options = {
	    zoomWidth: 400,
	    zoomHeight: 400,
        xOffset: 10,
        yOffset: 0,
        title: false
};

  
$(".jqzoom").jqzoom(options);
	
	$(".addpic").click(function(){
		src = $(this).attr('src');
		alt = $(this).attr('alt');
		$("#pic").html('');
		$("#pic").append('<a href="" id="mainpiclink"   class="jqzoom"><img src="" id="mainpic" /></a>')
		$("#pic").append("<br/><a href=\"javascript:open_window('"+alt+"',550,650)\">Полноразмерное изображение</a>");
		$("a#mainpiclink").attr( 'href', alt);
		$("#mainpic").attr( 'src', src);
	
		  	var options = {
	    zoomWidth: 400,
	    zoomHeight: 400,
            xOffset: 10,
            yOffset: 0,
            title: false //and MORE OPTIONS
          

               
};

  
$(".jqzoom").jqzoom(options);
	});
   
});


rollover =
{
   init: function()
   {
      this.preload();
     
      $(".ro").hover(
         function () {$(this).attr( 'src', rollover.newimage($(this).attr('src')) ); },
         function () {$(this).attr( 'src', rollover.oldimage($(this).attr('src')) ); }
      );
   },
 
 

   preload: function()
   {
      $(window).bind('load', function() {
         $('.ro').each( function( key, elm ) { $('<img>').attr( 'src', rollover.newimage( $(this).attr('src') ) ); });
      });
   },
   
   newimage: function( src )
   {
      return src.substring( 0, src.search(/(\.[a-z]+)$/) ) + '_w' + src.match(/(\.[a-z]+)$/)[0];
   },

   oldimage: function( src )
   {
      return src.replace(/_w\./, '.');
   }
};
