Cufon.replace('#categories_block_left ul.tree > li > a', {hover: true});

$(function() {
	if ($("#new_products_scroll li").size() > 0) {
		setInterval( "scrollNewProducts()", 4000 );
	}
	
	$("a.fancybx").fancybox({
		'titleShow'		: false,
		'transitionIn'	: 'elastic',
		'transitionOut'	: 'elastic',
		'overlayOpacity': 0.7
	});
	
	drawPopust();
	

});

function CheckStockMail() {
	var formdata = $("#ajaxstockform").serialize();
	
	$.ajax({ 
		type: "post",
		url: "/external/stockinfo.php",  
		data: formdata,  
		success: function(msg){
			if (msg == 'ok') {
				$("#checkstockmsg2").hide().html("<b>Vaš zahtevek za preverjanje zaloge je bil poslan. O stanju zaloge vas bomo obvestili na vaš E-poštni naslov.<br /><br /></b>").slideDown();
				$.fn.fancybox.close();
			} else {
				$("#checkstockmsg").html('<b><span style="color: #cc0000;">' + msg +'</span></b>');
			}
		}
	});  
	return false;
}

var new_p_idx = -1;
function scrollNewProducts() {
	var t_idx = 0;
	var next_p_idx = new_p_idx + 1;
	if (next_p_idx >= $("#new_products_scroll li").size()) {
		next_p_idx = 0;
	}
	var hideP;
	var showP;
	$("#new_products_scroll li").each(function() {
		if (t_idx == new_p_idx) {
			$(this).fadeOut('slow');
		}
		if (t_idx == next_p_idx) {
			$(this).fadeIn('slow');
		}
		t_idx++;
	});
	new_p_idx = next_p_idx;
}

function drawPopust() {
	$(".izdelekPopust").each(function() {
		var popust=$(this).html();
		if (popust) {
			var flashObj = $.flash.create({
				swf: '/themes/itaksport/img/popust.swf',
				flashvars: {
					'popust': popust
				},
				wmode: 'transparent',
				width: 65,
				height: 45,
			});
			$(this).html(flashObj);
		}
	});
	setTimeout("equalH()",100);
}


$.fn.equalHeight = function () {
    var height        = 0;
    var maxHeight    = 0;

    // Store the tallest element's height
    this.each(function () {
        height        = $(this).outerHeight();
        maxHeight    = (height > maxHeight) ? height : maxHeight;
    });

    // Set element's min-height to tallest element's height
    return this.each(function () {
        var t            = $(this);
        var minHeight    = maxHeight - (t.outerHeight() - t.height());
        var property    = $.browser.msie && $.browser.version < 7 ? 'height' : 'min-height';

        t.css(property, minHeight + 'px');
    });
};

function equalH() {
	$('ul#product_list .prodPrices').equalHeight();
	$('ul#product_list li').equalHeight();
	$('.product_list_small h3').equalHeight();
	var height        = 0;
    var maxHeight    = 0;

    // Store the tallest element's height
    $('ul#product_list li').each(function () {
        height        = $(this).outerHeight();
        maxHeight    = (height > maxHeight) ? height : maxHeight;
    });
}
$(document).ready(function(){
	equalH();
});

