jQuery.noConflict();

jQuery(function($) { 
	
	//Tables
	$('tr:odd').addClass('odd');
	
	$('tr td h2').parent().parent().addClass('headerLetter');
	
	//Tabs
	$('#specs').tabs();
	
	//Homepage latest product overlay
	/*if (document.getElementById('home')){
		var $latestProduct = $('#content > .csc-default').eq(1);
		$('a:first', $latestProduct).clone().addClass('overlay').empty().appendTo($latestProduct);
	}*/
	// valign images
 	if($('.item .image')[0]){
  		$('.item .image img').vAlign();
 	}
 	
 	//Gallery
 	
 	$('#product-single .news-single-img').find('p').remove();
 	
	$.fn.cycle.updateActivePagerLink = function(pager, currSlideIndex) { 
	    $(pager).find('li').removeClass('active') 
	        .filter('li:eq('+currSlideIndex+')').addClass('active'); 
	}; 
	
	$('#product-single .news-single-img').after('<ul id="gallery-nav">').cycle({
		fx:     'scrollBothWays', 
	    timeout: 0, 
	    pager:  '#gallery-nav',	    
	    speed: 300,
		pagerAnchorBuilder: function(idx, slide) {
			img = slide.getElementsByTagName('img')[0];
			
			var newImg = $(img).clone().appendTo('body'),
				height = newImg.height(),
				width = newImg.width();
				
			newImg.remove();
			
			var marginTop = -height*48/width/2;
			
        	return '<li><a href="#"><img src="'+img.src+'" width="48" style="margin-top: '+marginTop+'px"/></a></li>';
    	} 
	});
	
	//Carousel
	function thumbs_initCallback(carousel) {
		$('.next').bind('click', function() {
	        carousel.options.scroll = 1;
			carousel.next();
	        return false;
	    });

	    $('.prev').bind('click', function() {
	        carousel.options.scroll = 1;
	    	carousel.prev();
	        return false;
	    });

	}; 
	$('#gallery-nav:not(:empty)').jcarousel({ initCallback: thumbs_initCallback });

	var maxHeight = 0;
	$('.news-single-img').find('img').each(function(){
		if (parseInt($(this).attr('height')) > maxHeight) maxHeight = parseInt($(this).attr('height'));
	});

 	$('.news-single-img').find('img').each(function(){
 		var $imgHeight = $(this).attr('height');
 		var $imgWidth = $(this).attr('width');
 		var $linkHeight = $(this).parent().parent().height();
 		
 		$(this).parent().css('height',maxHeight);
 		$(this).parent().parent().css('height',maxHeight); 		
 		
 		if( $linkHeight > $imgHeight ){
 			$(this).css({
 				position: 'absolute',
 				marginTop: -$imgHeight/2,
 				marginLeft: -$imgWidth/2,
 				top: '50%',
 				left: '50%'
 			})
 		}
 	})
 	
 	//Lightbox
 	$('#product-single .news-single-img').find('a').removeAttr('onclick').attr('rel','group').fancybox({
		//type: 'ajax'
	});
	
	//Mark as checked activate newsletter
	$('#tx-srfeuserregister-pi1-module_sys_dmail_newsletter').attr('checked', true);
	
	$('#home #content > div').each( function(){
	    
	    $(this).find('.text p:last').addClass('withsep');
		
	});
	
 	
});

