var bodyheight=jQuery('body').height()-293;
jQuery(document).ready(function(){
	// initialize the gallery slideshow
	jQuery('.my-custom-cart').click(function(){
		window.location.href='http://www.wuillemin-fleuristes.ch/fleurs/checkout/cart/';
	});
});
var interval;
function theRotator(intv) {
	if (intv == null){
	   intv = 4000;
	 }
	//Set the opacity of all images to 0
	jQuery('div#rotator ul li').css({opacity: 0.0});
	
	//Get the first image and display it (gets set to full opacity)
	jQuery('div#rotator ul li:first').css({opacity: 1.0}).addClass('show');
		
	//Call the rotator function to run the slideshow, 6000 = change to next image after 4 seconds
	 clearInterval(interval);
	 
	 interval=setInterval('rotate(); rotate("prev")',intv);
	
}
function rotate(dir) {	
	
	//Get the first image
	var current = (jQuery('div#rotator ul li.show')?  jQuery('div#rotator ul li.show') : jQuery('div#rotator ul li:first'));

	//Get next image, when it reaches the end, rotate it back to the first image
	var next;
	if(dir=='prev'){
		next = ((current.prev().length) ? ((current.prev().hasClass('show')) ? jQuery('div#rotator ul li:last') :current.prev()) : jQuery('div#rotator ul li:last'));	
	} else {
		next = ((current.next().length) ? ((current.next().hasClass('show')) ? jQuery('div#rotator ul li:first') :current.next()) : jQuery('div#rotator ul li:first'));	
	}
	var nextheight=next.height();
	jQuery('#rotator ul').css('height', (nextheight)+'px');
	jQuery('body').css('height', (bodyheight+nextheight)+'px');
	//Set the fade in effect for the next image, the show class has higher z-index
	next.css({opacity: 0.0})
	.addClass('show')
	.animate({opacity: 1.0}, 1500);
	
	var cur_count=next.attr('id').split('_')[1];
	jQuery('#rotator .gcurrent').text(cur_count);

	//Hide the current image
	current.animate({opacity: 0.0}, 1000)
	.removeClass('show');
	
	clearInterval(interval);
	 
	 interval=setInterval('rotate()',4000);
	
};
function showGallery(gallery){
	jQuery('.gallery').attr('id','');
	jQuery('.gallery.'+gallery).attr('id','rotator');
	jQuery('.left-sidebar a.active').removeClass('active');
	jQuery('a#link-'+gallery).addClass('active');
	jQuery('.'+gallery+' .gcurrent').text('1');
	theRotator(1);
}
function myAddToCart(id){
	jQuery('#atc_button_'+id).addClass('loading');
	jQuery('#atc_button_'+id).blur();
	jQuery('#atc_button_'+id).attr('disabled', 'disabled');
	var url=jQuery('#addtocart-'+id+' .atc_url').val();
	var pars='?super_attribute[525]='+jQuery('#addtocart-'+id+' .productsize-dd').val()+'&qty='+jQuery('#addtocart-'+id+' .my_quantity').val();
	jQuery.get(url+pars,function(data){
		jQuery('#addtocart-'+id+' .success-added').slideDown('slow', function callback(){
			jQuery('#atc_button_'+id).removeClass('loading');
			jQuery('#atc_button_'+id).attr('disabled', '');
			jQuery.get('http://www.wuillemin-fleuristes.ch/fleurs/js/ajax/updatecart.php', function(data){jQuery('.my-custom-cart').html(data);});
		});
	})
}
function setMenuActive(id){
	jQuery(document).ready(function(){
		jQuery('.pages-menu li.active').removeClass('active');
		jQuery('li#'+id).addClass('active');
	});
}
var qtyvalue=1;
function focusBlur(id){
	qtyvalue=jQuery('#addtocart-'+id+' .my_quantity').val();
	jQuery('#addtocart-'+id+' .my_quantity').val('');
}
