$(document).ready(function()
{
	$("#comments_slider").cycle({fx:"scrollDown",speed:300,timeout:7000,cleartype:1,pause:1});
	$("#baner_slider").cycle({fx:"fade",speed:300,timeout:6000,cleartype:1,pager:"#baner_nav",pause:1});
	$("#right_baner").cycle({fx:"scrollUp",speed:300,timeout:4000,cleartype:1,pause:1});

	
	if ($("#browser_alert").length)
	{
		$("#mask").fadeIn(200);
		$("#browser_alert").fadeIn(200);
	}

	$("#showlog").click(function()
	{
		$("#right_menu").animate({"opacity":0},300,function()
		{
			$("#right_menu").css("display","none");
			$("#login_container").animate({"top":0},300);
		});
	});

	$("#closelog").click(function()
	{
		$("#login_container").animate({"top":"-55px"},300,function()
		{
			$("#right_menu").css("display","block").animate({"opacity":1},300);
		});
	});

	$(".clear_click").click(function()
	{
		if ($(this).attr("value")=="login" || $(this).attr("value")=="password")
		{
			$(this).attr("value","");
		}
	});

	$(".clear_click").focus(function()
	{
		if ($(this).attr("value")=="login" || $(this).attr("value")=="password")
		{
			$(this).attr("value","");
		}
	});
	

	$(".gallery a").lightBox({txtImage:"&nbsp;",txtOf:"/"});
	
	$(".gallery div.inside").hover(function()
	{
		$(this).stop(true,true).animate({width:"145px",height:"145px"},100);
	},function()
	{
		$(this).stop(true,true).animate({width:"135px",height:"135px"},100);
	});
	
	
	
	
	
	$(".bt_active").live("click",function()
	{
		var cid=$(this).attr("id");
		var cid2=cid.split("_");
		cid=cid2[1];
		
		$("#sub2_menu span").removeClass("bt_noactive").addClass("bt_active");
		$(this).removeClass("bt_active").addClass("bt_noactive");
		
		$(".div_field").hide();
		$("#field"+cid).show();
	});
	
	
	
	

	

	$(".wzory_okladek a").lightBox({txtImage:"&nbsp;",txtOf:"/"});
	
	$(".wzor_okladki").hover(function()
	{
		$(this).stop(true,true).animate({width:"140px",height:"93px"},100);
	},function()
	{
		$(this).stop(true,true).animate({width:"130px",height:"86px"},100);
	});
	
	
	
	
	
	if ($("#video_container1").length) jwplayer("video_container1").setup({flashplayer:"addons/jwplayer/player.swf",file:"download/movies/photo_book.mp4",height:350,width:540,autostart:false,plugins:{sharing:{link:false}}});
	if ($("#video_container2").length) jwplayer("video_container2").setup({flashplayer:"addons/jwplayer/player.swf",file:"download/movies/klejarka.mp4",height:350,width:540,autostart:false,plugins:{sharing:{link:false}}});
	if ($("#video_container3").length) jwplayer("video_container3").setup({flashplayer:"addons/jwplayer/player.swf",file:"download/movies/stol.mp4",height:350,width:540,autostart:false,plugins:{sharing:{link:false}}});
	
	if ($("#video_container4").length) jwplayer("video_container4").setup({flashplayer:"addons/jwplayer/player.swf",file:"download/movies/instalacja.mp4",height:350,width:540,autostart:false,plugins:{sharing:{link:false}}});
	if ($("#video_container5").length) jwplayer("video_container5").setup({flashplayer:"addons/jwplayer/player.swf",file:"download/movies/funkcja_sender.mp4",height:350,width:540,autostart:false,plugins:{sharing:{link:false}}});
	if ($("#video_container6").length) jwplayer("video_container6").setup({flashplayer:"addons/jwplayer/player.swf",file:"download/movies/tworzenie_albumu.mp4",height:350,width:540,autostart:false,plugins:{sharing:{link:false}}});
	if ($("#video_container7").length) jwplayer("video_container7").setup({flashplayer:"addons/jwplayer/player.swf",file:"download/movies/tworzenie_szablonu.mp4",height:350,width:540,autostart:false,plugins:{sharing:{link:false}}});


	$('#podglad_wzor a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt1 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt2 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt3 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt4 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt5 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt6 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	$('.gt7 a').lightBox({txtImage:"&nbsp;",txtOf:"/"});
	
	
	
	if ($("#confirm_user_alert").length)
	{
		$("#mask").fadeIn(200);
		$("#confirm_user_alert").fadeIn(200);
	}




	$("#icon_admin").click(function()
	{
		var field_height=$("#field_height").attr("value");
		
		if ($("#admin_panel").css("width")=="50px")
		{
			$("#admin_panel").animate({"width":"250px","height":field_height,"background-color":"#2c4e75"},100,function()
			{
				$("#panel_field").fadeIn(200);
			});
		}
		else
		{
			$("#panel_field").hide();

			$("#admin_panel").animate({"width":"50px","height":"50px","background-color":"#2869b1"},100,function(){});
		}
	});





	$('#icon_admin').hover(function(){$(this).css("opacity",0.8);},function(){$(this).css("opacity",1);});
	
	
	
	
	$("#alert").fadeIn(200).delay(1500).fadeOut(200,function()
	{
		$("#log_form").fadeIn(200);
	});



	$("#price_container #rabat,#price_container #price,#price_container #loader_price,").css("opacity",0);
	
	
	$(window).scroll(function()
	{
		$("#temp").attr("value",$(window).scrollTop());
		
		if ($(window).scrollTop()>460)
		{
			$("#bg_floating").stop(true,false).animate({"top":$(window).scrollTop()-485},300);
			$("#price_mask").stop(true,false).animate({"height":$(window).scrollTop()-420},300);
		}
		else
		{
			$("#bg_floating").stop(true,false).animate({"top":"-41px"},300);
			$("#price_mask").stop(true,false).animate({"height":"10px"},300);
		}
		
		
		var scroll_thumb_after=$("#scroll_thumb_after").attr("value");
		
		if ($(window).scrollTop()>scroll_thumb_after) $("#ajax_color_thumb").stop(true,false).animate({"margin-top":$(window).scrollTop()-scroll_thumb_after},300); else $("#ajax_color_thumb").stop(true,false).animate({"margin-top":0},300);		
	});

	
	$(".tooltip,.tooltip2").style_my_tooltips(
	{
		tip_follows_cursor:"on",
		tip_delay_time:200
	});	











	if ($("#confirm_user_alert").length)
	{
		$("#mask").fadeIn(200);
		$("#confirm_user_alert").fadeIn(200);
	}





	$('.products_table .single_product').hover(function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");
		
		$(".products_table #product_"+exp[1]+" td").css("border-color","#333");
	},
	function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");
		
		$(".products_table #product_"+exp[1]+" td").css("border-color","#ddd");
	});





	$('.products_table .komorka').hover(function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");
		
		$(".products_table #product_"+exp[1]+" td").css("border-color","#333");
	},
	function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");
		
		$(".products_table #product_"+exp[1]+" td").css("border-color","#ddd");
	});





	$(".single_order .td_href").click(function()
	{
		var c_id=$(this).parent().attr("id");
		var exp=c_id.split("_");

		$("#details"+exp[1]).removeClass("details");
		$(".details").hide();
		$("#details"+exp[1]).addClass("details");
		$("#details"+exp[1]).fadeToggle(300);
	});


	$(".hide_details").click(function()
	{
		$(".details").hide(300);
	});


	$("#sql_filter select").change(function(){$("#sql_filter").submit();});


	$(".single_product .td_href").click(function()
	{
		var c_id=$(this).parent().attr("id");
		var exp=c_id.split("_");

		$("#mask").fadeIn(200);
		$("#product_details").show();
		$("#product_details div").show();
		$("#field_comments").hide();
		$("#bt_comments_hide").hide();
		$("#bt_comments").show();
		$("#loader_details").show();
		$("#ajax_details").html("");
		$("#product_status").html("&nbsp;");
		$("#content_comments").attr("value",$("#default_content").attr("value")).css("color","#aaa");

		$.ajax(
		{
			url:"include/ajax_actions.php?action=load_product_details&product_id="+exp[1],
			success:function(data)
			{
				var exp=data.split("|");
				
				$("#ajax_details").html(exp[0]);
				$("#mcs_container").mCustomScrollbar("vertical",300,"easeOutCirc",1.05,"auto","yes","yes",15);
				$("#loader_details").fadeOut(500);
				$("#product_status").html(exp[1]);
			}
		});
	});


	$("#bt_comments").click(function()
	{
		$("#field_comments").slideDown(200);
		$(this).hide();
		$("#bt_comments_hide").show();
	});


	$("#content_comments").focus(function()
	{
		$(this).css("color","#333");

		if ($(this).attr("value")==$("#default_content").attr("value")) $(this).attr("value","");
	});


	$("#bt_comments_hide").click(function()
	{
		$("#field_comments").slideUp(200);
		$(this).hide();
		$("#bt_comments").show();
	});


	$("#send_comments").click(function()
	{
		var product_id=$("#product_id").attr("value");
		$("#loader_comments").show();
		convertPL("content_comments");

		$.ajax(
		{
			type:"POST",
			url:"include/ajax_actions.php?action=send_comments&product_id="+product_id,
			data:$("#form_comments").serialize(),
			success:function(data)
			{
				$("#loader_comments").hide();
				$("#bt_comments_hide").hide();
				$("#content_comments").attr("value","").css("color","#333");;
				
				$("#field_comments").slideUp(200,function()
				{
					$("#info_comments").fadeIn(200).delay(4000).fadeOut(200,function(){$("#bt_comments").show();});
				});
			}
		});
	});






	$(".bt_comments_order").click(function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");
		
		$(".popup_comments").fadeOut(200);
		$("#popup_comments_order_"+exp[3]).fadeIn(200);
	});


	$(".close_comments_order").click(function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");
		
		$("#popup_comments_order_"+exp[3]).fadeOut(200);
	});


	$(".save_comments_order").click(function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");

		if ($("#comments_order_"+exp[3]).attr("value")!="")
		{		
			$("#loader_comments_order_"+exp[3]).fadeIn(100);
			
			convertPL("comments_order_"+exp[3]);

			$.ajax(
			{
				type:"POST",
				url:"include/ajax_actions.php?action=save_comments_order&order_id="+exp[3],
				data:$("#form_comments_order_"+exp[3]).serialize(),
				success:function(data)
				{
					$("#loader_comments_order_"+exp[3]).fadeOut(300);
					
					$("#show_comments_order_"+exp[3]).html(data);					
					$("#comments_order_"+exp[3]).attr("value","");
					$("#bt_comments_order_"+exp[3]).removeClass("bt_gray").attr("title",$("#bt_comments_order_"+exp[3]).attr("alt"));
					
					convertISO("comments_order_"+exp[3]);
				}
			});
		}
	});	










	$(".bt_comments_product").click(function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");
		
		$(".popup_comments").fadeOut(200);
		$("#popup_comments_product_"+exp[3]).fadeIn(200);
	});


	$(".close_comments_product").click(function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");
		
		$("#popup_comments_product_"+exp[3]).fadeOut(200);
	});


	$(".save_comments_product").click(function()
	{
		var c_id=$(this).attr("id");
		var exp=c_id.split("_");

		if ($("#comments_product_"+exp[3]).attr("value")!="")
		{		
			$("#loader_comments_product_"+exp[3]).fadeIn(100);
			
			convertPL("comments_product_"+exp[3]);

			$.ajax(
			{
				type:"POST",
				url:"include/ajax_actions.php?action=save_comments_product&product_id="+exp[3],
				data:$("#form_comments_product_"+exp[3]).serialize(),
				success:function(data)
				{
					$("#loader_comments_product_"+exp[3]).fadeOut(300);
					
					$("#show_comments_product_"+exp[3]).html(data);					
					$("#comments_product_"+exp[3]).attr("value","");
					$("#bt_comments_product_"+exp[3]).removeClass("bt_gray").attr("title",$("#bt_comments_product_"+exp[3]).attr("alt"));
					
					convertISO("comments_product_"+exp[3]);
				}
			});
		}
	});
	
	
	
	
	
	$(".file_field").hover(function(){$(this).stop(true,true).css("border-color","#eee");},function(){$(this).stop(true,true).css("border-color","#fff");});
	
	$(".download").hover(function(){$(this).stop(true,true).css("background-color","#0086e1");},function(){$(this).stop(true,true).css("background-color","#0469ae");});
	
	
	
	
	$(".folder").live("click",function()
	{
		var folder=$(this).attr("title");
		var current_dir=$("#current_dir").attr("value");
		
		$("#current_dir").attr("value",current_dir+"/"+folder);
		
		$.ajax(
		{
			type:"POST",
			url:"file_explorer.php",
			data:$("#form_file_explorer").serialize(),
			success:function(data)
			{
				$("#file_explorer").animate({"opacity":0},200,function()
				{
					$("#file_explorer").html(data).animate({"opacity":1},200);
				});
			}
		});		
	});
	
	
	
	
	$(".folder_back").live("click",function()
	{
		var current_dir=$("#current_dir").attr("value");
		
		var exp_cdir=current_dir.split("/");
		var back_dir="";

		for (z=0; z<exp_cdir.length; z++)
		{
			if (z<(exp_cdir.length-1))
			{
				back_dir+=exp_cdir[z];
			}
		}
		
		$("#current_dir").attr("value",back_dir);
		
		$.ajax(
		{
			type:"POST",
			url:"file_explorer.php",
			data:$("#form_file_explorer").serialize(),
			success:function(data)
			{
				$("#file_explorer").animate({"opacity":0},200,function()
				{
					$("#file_explorer").html(data).animate({"opacity":1},200);
				});
			}
		});		
	});	
});



function gotourl(link)
{
	window.location.href=link;
}



function focus_input(input_name,message)
{
	document.getElementById(input_name).focus();
	//document.getElementById(input_name).style.backgroundColor="#e1e1e1";
	//window.scrollBy(0,-50);
	window.alert(message);
}
