function video(){
	if($.browser.webkit)
            window.open('live/video.php', "video_popup",'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=940,height=483,top=0,left=0');
    if($.browser.mozilla)
            window.open('live/video.php', "video_popup",'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=940,height=483,top=0,left=0');
    if($.browser.msie)
            window.open('live/video.php', "video_popup",'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=940,height=483,top=0,left=0');
    if($.browser.opera)
            window.open('live/video.php', "video_popup",'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=940,height=483,top=0,left=0');
    
}

function addToCart(pid, el, reload_after){
	$('html, body').animate({scrollTop:0}, 'slow');
	$.post("?mod=store&action=cart", "do=ajaxAddToCart&product_id="+pid, function(data){
			$("#cart").html(data);
			initCartButtons();
			cl_hide();
		}
	);
	
	if($("#cart").css("display") == "none"){
		$("#cart").slideToggle(function(){
			bindDocumentClick();
	      	transfer(el, function(){
	      		if(reload_after == 1){
	      			window.location = window.location;
				}	
	      	});
	      	
		});				
	}
	else{
		transfer(el, function(){
	      		if(reload_after == 1){					
	      			window.location = window.location;
				}	
	      	});
	}	
}

function fancyTables(){
        var tables = $('table.fancytable');
        for(var i=0; i<tables.length; i++){
                if($(tables[i]).hasClass("firstfirst")){
                	$(tables[i]).find("tr:first").addClass("zSelected");
                }
                $(tables[i]).find("tr:odd").addClass("zOdd");
                $(tables[i]).find("tr:even").addClass("zEven");
        }
}

function transfer(from_el, on_finish){
	from_el.effect("transfer", { to: $("#cart") }, 1000, on_finish);
	var html = '<table width="100%" height="100%"><tr><td valign="bottom"><div style="background:#fff; float:left; border:2px solid #902900;">';
	html += from_el.html();
	html += '</div></td></tr></table>';
	$(".ui-effects-transfer").html(html);
}

function initCartButtons(){	
	$(".cart_minus").click(function(){
		cl_show();
		$.post("?mod=store&action=cart", "do=cartminus&cid="+$(this).attr("cart_id"), function(data){
			$("#cart").html(data);
			initCartButtons();
			cl_hide();
		})		
	});
	$(".cart_plus").click(function(){
		cl_show();
		$.post("?mod=store&action=cart", "do=cartplus&cid="+$(this).attr("cart_id"), function(data){
			$("#cart").html(data);
			initCartButtons();
			cl_hide();
		})		
	});
}

function bindDocumentClick(){
	$(document).bind('click.ccc', function(e){
		$("#cart").fadeOut();
		unBindDocumentClick();
	});
	
	$('#cart').click(function(e) {
	  e.stopPropagation();
	});
	$('a.addtocart').click(function(e) {
	  e.stopPropagation();
	});


}

function cl_show(){
	$("#cl").fadeIn();
}
function cl_hide(){
	$("#cl").fadeOut();
}

function unBindDocumentClick(){
	$(document).unbind('.ccc');
}

$(function(){
	
	$("a.addtocart").click(function(e){
		cl_show();
		e.preventDefault();
		addToCart($(this).attr("pid"), $(this).parent(), $(this).attr("reload_after"));
	});
	
	$("#vzivo").click(function(e){
		e.preventDefault();
        video();
    });	
    
    $(".cart_toggle").click(function(e){
    	e.preventDefault();
		$("#cart").slideToggle(function(){
			if($("#cart").css("display") != 'none'){
				bindDocumentClick();
			}
			else {
				unBindDocumentClick();
			}
		});		
		return false;
	});
	   
	initCartButtons();
	
	$(".ui-tabs-nav").tabs(".ui-tabs-panel",{event:'mouseover',effect:'fade',rotate:true, fadeOutSpeed:400}).slideshow({interval:5000,autoplay:true,clickable:false});
	$("#tabsi ul.tabs").tabs(".tab_container .tab_content",{ effect:'fade', fadeOutSpeed:400});

});
