// Font Replacement
Cufon.replace('.category-title h1,.footer h4, .product-view .product-shop .product-name h1,.page-title h1, .page-title h2,.home .subscribe strong', {
	hover: true
});

function roundedCorners() {
	var img = jQuery(this);
	var img_width = img.width();
	var img_height = img.height();
 
	// build wrapper
	var wrapper = jQuery('<div class="rounded_wrapper"></div>');
	wrapper.width(img_width);
	wrapper.height(img_height);
 
	// move CSS properties from img to wrapper
	wrapper.css('float', img.css('float'));
	img.css('float', 'none')
 
	wrapper.css('margin-right', img.css('margin-right'));
	img.css('margin-right', '0')
 
	wrapper.css('margin-left', img.css('margin-left'));
	img.css('margin-left', '0')
 
	wrapper.css('margin-bottom', img.css('margin-bottom'));
	img.css('margin-bottom', '0')
 
	wrapper.css('margin-top', img.css('margin-top'));
	img.css('margin-top', '0')
 
	wrapper.css('display', 'block');
	img.css('display', 'block')
 
	// IE6 fix (when image height or width is odd)
	if (jQuery.browser.msie && jQuery.browser.version == '6.0') {
		if(img_width % 2 != 0) {
			wrapper.addClass('ie6_width')
		}
		if(img_height % 2 != 0) {
			wrapper.addClass('ie6_height')			
		}
	}
 
	// wrap image
	img.wrap(wrapper);
 
	// add rounded corners
	img.after('<div class="tl"></div>');
	img.after('<div class="tr"></div>');
	img.after('<div class="bl"></div>');
	img.after('<div class="br"></div>');
}

function sliderTabBuilder(index, tab) {
	// replace existing tab content (so that jQuery can add their event handlers)
	var tabContent = '';
	var tabElement = jQuery('#slider').find('li:eq(' + index + ')').find('div.tab');
	if (tabElement.html()) {
		tabContent = tabElement.html();
		tabElement.remove();
	} else if ( jQuery('#slider').find('li:eq(' + index + ')').find('div.title').html()) {
		tabContent = '<h1>' + jQuery('#slider').find('li:eq(' + index + ')').find('div.title').html() + '</h1>'
	}
	return '<li>' + tabContent + '</li>';
}

function justifySliderTabs() {
	var width = jQuery('#slidercontrols').width();
	var tabCount = jQuery('#slidercontrols > li').size();
	var tabWidth = width / tabCount;
	jQuery('#slidercontrols > li').each(function(index, element) {
		var widthDelta = jQuery(this).outerWidth(true) - jQuery(this).width();
		jQuery(this).width(tabWidth - widthDelta);
	});
}

jQuery(document).ready(function() {
	// rounded images
	jQuery('.rounded').each(roundedCorners);
	/*jQuery('.rounded').one('load', roundedCorners).each(function() {
		if(this.complete) jQuery(this).trigger("load");
	});*/
	// Featured Products
    jQuery('#featured').jcarousel();
	// FancyBox jQuery
	jQuery("a.group").fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true }); 	
	// Slider Homepage
	jQuery('#slider').cycle({
        fx: 'scrollLeft',
        speed: 1000,
		timeout: 5000,
        pager: '#slidercontrols',
        pagerEvent: 'mouseover',
        pagerAnchorBuilder: sliderTabBuilder,
        pause: true,
        pauseOnPagerHover: true,
		slideExpr: '.panel',
		fastOnEvent: false
    });
	justifySliderTabs();
});

