function shoppingCart(id, action) {
	$.get('/shopcart/shopcart.php', { 'prid': id, 'action': action }, 
		function(data) {
			data = '<h2 align="center" style="padding: 50px;">'+data+'</h2>';
			$.fancybox(data, {
      	'autoDimensions'	: false,
				'width'         	: 350,
				'height'        	: 'auto',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'overlayOpacity'	: 0.8,
				'overlayColor'		: '#000'
			});
			
			$('div#item_'+id).hide();
			if (action == 'add') {
				$('div.webpay').remove();
			}			
	});
}


function formatTitle(title, currentArray, currentIndex, currentOpts) {
    return '<div id="tip7-title"><span><a href="javascript:;" onclick="$.fancybox.close();"><img src="/images/closelabel.gif" /></a></span>' + (title && title.length ? '<b>' + title + '</b>' : '' ) + 'Imagen ' + (currentIndex + 1) + ' of ' + currentArray.length + '</div>';
}

function get_products(termID, termSlug, taxName) {
	$.get('/includes/ajax-getproducts.php', {
			'term_id': termID,
			'term_slug': termSlug,
			'tax_name': taxName
		}, function(data) {
				$('div#static-content').hide();
				$('div#ajax-response').hide();
				$('div#ajax-response').html(data).show('slow');	
		}
	);
}

function cotizar() {
	$.post('/includes/doFeedback.php', $('#cotizarForm').serialize(), 
		function(data) {	
			$.fancybox(data, {
	      'autoDimensions'	: false,
				'width'         	: 350,
				'height'        	: 'auto',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'overlayOpacity'	: 0.8,
				'overlayColor'		: '#000'
			});
	});
}

function regenerate_borders() {
	$(".pp_smallpic").load(function() {
		$(this).wrap(function(){
			return '<span class="' + $(this).attr('class') + '" style="background:url(' + $(this).attr('src') + ') no-repeat center center; width: ' + $(this).width() + 'px; height: ' + $(this).height() + 'px;" />';
		});
		$(this).css("opacity","0");
	});
	
	// <span class="pp_smallpic" style="background:url() no-repeat center center; width: 115px; height: 110px;" />	
}

$(document).ready(function(){
	
	//regenerate_borders();
	
	// tabs, must be declined manually
	$("ul#soportepanes").tabs("div.panes > div", {effect: 'slide', speed: 100});
	$("ul.product_nav").tabs("div.panes > div", {effect: 'fade', speed: 100});
	$("ul.valores_list").tabs("div.valpanes > div", {effect: 'fade', speed: 100});

	
	$("ul.valores_list li a").click(function() {
		$("ul.valores_list li a").removeClass("active_price");
		$(this).addClass("active_price");
	});
	
	$("ul.product_nav li a").click(function() {
		$("ul.product_nav li a").removeClass("active_nav");
		$(this).addClass("active_nav");
	});
	
	$("ul.menu_list li a").click(function() {
		$("ul.menu_list li a").removeClass("active");
		$(this).addClass("active");
	});	
	
	$("ul#navS li a").click(function() {
		$("ul#navS li a").removeClass("active_sw");
		$(this).addClass("active_sw");
	});	
	
	$("a.subnivel").click(function() {
		$("a.subnivel").removeClass("active_subnivel");
		$(this).addClass("active_subnivel");
	});	
	
	$("div#slideshow a").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	true,
		'cyclic': true,
		'showNavArrows': true,
		
		'titlePosition' 		: 'inside',
		'titleFormat': formatTitle
	});

	$('#imprimirm').click(function(){
		$('.ficha_producto').jqprint();
		return false;
	});
	
});

$(function() {
	$('#slideshow').cycle({
		fx:     'fade',
		speed:  'fast',
		timeout: 0,
		pager:  '#nav',       
		pagerAnchorBuilder: function(idx, slide) { 
	  	return '#nav li:eq(' + (idx) + ') a'; // return sel string for existing anchor
		} 
	});
	
	$("a.comollegar").fancybox({
    'autoDimensions'	: false,
		'width'         	: 640,
		'height'        	: 480,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'overlayOpacity'	: 0.8,
		'overlayColor'		: '#000'		
	});	

	$('.cnt_rotator').cycle({
		fx:     'scrollLeft',
		timeout: 0,
		delay:  -1000,
		pager:  '#navS',       
		pagerAnchorBuilder: function(idx, slide) {
	    return '#navS li:eq(' + (idx) + ') a'; // return sel string for existing anchor
		}
	});

	$("div#makeMeScrollable").smoothDivScroll({ autoScroll: "onstart", 
												autoScrollDirection: "endlessloopright",
												autoScrollStep: 1,
												autoScrollInterval: 15,
												// startAtElementId: "startAtMe",
												visibleHotSpots: "always" });
});
