var ajuste_x = 0;
var ajuste_y = 0;
var browser=navigator.appName;
var highlight_menu='';
var selected_pic;

$(document).ready(function() {
	$.preLoadImages('http://localhost/mitemiteshop/themes/mitemite/img/homepic_big.jpg');
	if (browser=="Microsoft Internet Explorer"){
		ajuste_x = 4;
		ajuste_y = 4;
		if($(document).height()-ajuste_y>$('body').height()) ajuste_x +=17;
	}
	
	var slider1 = $('#photos .imgCarousel ul').bxSlider({
		displaySlideQty: 4,
		moveSlideQty: 1       
	});
	
	var slider2 = $('#product-main-image ul').bxSlider({
		displaySlideQty: 1,
		moveSlideQty: 1,
		onAfterSlide: function(current, total, currentSlideHtmlObject){
			$('#product-image-list .product-image').each(function(){
				$(this).css('border-color','#fff');
			});
			selected_pic=current;
			$('#product-image-list .product-image[name=product'+selected_pic+']').css('border-color','#ec008c');
		}
	});
	
		
	$('#product-image-list .product-image').click(function(){
		var nombre=$(this).attr('name');
		nombre=nombre.substr(7);
		selected_pic=parseInt(nombre);
		$('#product-image-list .product-image').each(function(){
			$(this).css('border-color','#fff');
		});
		$(this).css('border-color','#ec008c');
		slider2.goToSlide(selected_pic);
	});
	
	$('#product-image-list .product-image').mouseover(function(){
		var nombre=$(this).attr('name');
		nombre=nombre.substr(7);
		$(this).css('border-color','#ec008c');
	});
	
	$('#product-image-list .product-image').mouseout(function(){
		var nombre=$(this).attr('name');
		nombre=nombre.substr(7);
		if(nombre!=selected_pic)
			$(this).css('border-color','#fff');
	});

	Shadowbox.init({
		handleOversize: "drag",
		modal: true
	});

	
	$("#buscar").dialog({
			resizable: false,
			autoOpen: false,
			height:140,
			modal: true,
			buttons: {
				'Buscar': function() {
					$(this).dialog('close');
				}
			}
		});
	$('#lupa img').click(function() {
		$('#buscar').dialog('open');
		});
	
	if($(".scroll-pane").length>0)
		$(".scroll-pane").jScrollPane();

	$(".right-links").mouseover( function(){
		$(this).parent().css('border','1px solid #ec008c');
	});
	
	$(".right-links").mouseout( function(){
		$(this).parent().css('border','1px  solid #fff');
	});
	
	$(".product").mouseover( function(){
		$(this).find('.over_div').addClass('show_elem');
		$(this).find('.over_div').removeClass('hide_elem');
		$(this).find('.out_div').addClass('hide_elem');
		$(this).find('.out_div').removeClass('show_elem');
	});
	
	$(".product").mouseout( function(){
		$(this).find('.over_div').removeClass('show_elem');
		$(this).find('.over_div').addClass('hide_elem');
		$(this).find('.out_div').removeClass('hide_elem');
		$(this).find('.out_div').addClass('show_elem');
	});
	
	$(".add_link").click( function(){
		$(this).parent().parent().parent().parent().submit();
	});
	
	$(".add_link").mouseover( function(){
		$(this).addClass('add_hover');
		$('#shopping-cart-box').animate({
			width: 'toggle',
			height: 'toggle'
		  }, {
			duration: 400, 
			specialEasing: {
			  width: 'easeOutBounce',
			  height: 'easeOutBounce'
			}, 
			complete: function() {
			}
		  });
	});
	
	$("#menu a").mouseover( function(){
		var tit = $(this).attr('title');
		$(this).find('img').attr('src','themes/mitemite/img/'+tit+'.png');
	});
	
	$("#menu a").mouseout( function(){
		var tit = $(this).attr('title');
		if(tit!=highlight_menu || highlight_menu=='')
			$(this).find('img').attr('src','themes/mitemite/img/'+tit+'_off.png');
	});
	
	$("input.imghover").mouseover( function(){
		var tit = $(this).attr('title');
		$(this).css('background','url(themes/mitemite/img/'+tit+'_off.png)');
	});
	
	$("input.imghover").mouseout( function(){
		var tit = $(this).attr('title');
		$(this).css('background','url(themes/mitemite/img/'+tit+'.png)');
	});
	
	$("img.imghover").mouseover( function(){
		var tit = $(this).attr('title');
		$(this).attr('src','themes/mitemite/img/'+tit+'_off.png');
	});
	
	$("img.imghover").mouseout( function(){
		var tit = $(this).attr('title');
		$(this).attr('src','themes/mitemite/img/'+tit+'.png');
	});
	
	$(".add_link").mouseout( function(){
		$(this).removeClass('add_hover');
		$('#shopping-cart-box').animate({
			width: 'toggle',
			height: 'toggle'
		  }, {
			duration: 400, 
			specialEasing: {
			  width: 'easeOutBounce',
			  height: 'easeOutBounce'
			}, 
			complete: function() {
			}
		  });
	});
	
	
	$("#menu a").each( function(){
		var tit = $(this).attr('title');
		if(tit==highlight_menu)
			$(this).find('img').attr('src','themes/mitemite/img/'+tit+'.png');
	});
	$(window).bind("resize", function(){
		$("#body-background").ezBgResize();
	});
	$("#body-background").ezBgResize();
});


(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)
