$("document").ready(function() {
	/*-- placeholder --*/
	$("input[placeholder]").placeholder();
	/*-- placeholder --*/

	/*-- add input --*/
	$("#add-first").click(function() {
		$("#product-name").append("<tr><td><input type='text' name='company[main_products][]' class='main-input' style='width: 220px;' /></td><td><input type='text' name='company[main_products_desc][]' class='main-input' style='width: 380px;' /></td></tr>");
		return false;
	});
	$("#add-second").click(function() {
		$("#other-product-name").append("<tr><td><input type='text' name='company[other_products][]' class='main-input' style='width: 620px;' /></td></tr>");
		return false;
	});
	/*-- add input --*/
	
	/*-- cuSel --*/
	$(".cusel").each(function() {
		var w = parseInt(jQuery(this).width()),	scrollPanel = jQuery(this).find(".cusel-scroll-pane");
		if(w>=scrollPanel.width()) {
			$(this).find(".jScrollPaneContainer").width(w);
			scrollPanel.width(w);
		}
	});
	var params = {
		changedEl: "select",
		visRows: 7
	}
	cuSel(params);
	/*-- cuSel --*/	
	
	/*-- modal-box --*/
	$("#modal-button").fancybox({	
		"centerOnScroll": true,
		"modal": true,
		"onComplete": function() {
			$("#rubric-select").css("display","block").css("width","210px");
			params = {
				refreshEl: "#rubric-select",
				visRows: 7
			}
			cuSelRefresh(params);			
		},
		"onClosed":	function() {
			$("#modal-box").parent().hide();
		}
	});
	$("#visit-button").fancybox({	
		"centerOnScroll": true,
		"scrolling": "no",
		"modal": true
	});
	/*-- modal-box --*/
	
	/*-- index.html gallery hint --*/
	var intervalID;
	$(".org-img").hover(
		function() {
			$(this).find(".img-gray").hide();
			var offLeft = $(this).parent().position();
			var scrPos = $(".jspPane").position();
			$(".fg-caption").css("left", offLeft.left - 110 + scrPos.left + "px");
			
			name = $(this).find("img").attr("alt");
			text = $(this).find("img").attr("title");
			$(".fg-caption").html("<span class='fg-caption-triangle png'></span><b>" + name + "</b>" + text);
			
			popup = $(".fg-caption");
			intervalID=setTimeout(function() {
				popup.fadeIn();
			}, 400);
		},
		function() {
			$(this).find(".img-gray").show();
			$(".fg-caption").hide();
			clearInterval(intervalID);
		}
	);
	/*-- index.html gallery hint --*/

	$("#catalog-firm").hover(
		function() {
			$(this).prepend("<span class='cf-triangle png'></span>");
		},
		function() {
			$(".cf-triangle").remove();
		}
	);
	
	
	
	
	/*-- top menu --*/
	$("#hm-menu > li").hover(
		function() {
			if($(this).hasClass("selected") != true ) $(this).addClass("item-hover");
			if($(this).hasClass("parent") == true) {
				$(this).addClass("parent-hover");
				$(this).find("#hm-sub-menu").show("fast");
			}
		},
		function() {
			$(this).removeClass("item-hover");
			if($(this).hasClass("parent") == true) {
				$(this).removeClass("parent-hover");
				$(this).find("#hm-sub-menu").hide("fast");
			}
		}
	);
	/*-- top menu --*/
	
	
	
	$("#fg-panel").jScrollPane();({
		horizontalDragMinWidth: 17
	});	
	
	$("a.move-right").click(function() {
		var li_count = 21;
		var pos = parseInt($(this).attr("id"), 10);
		var kol = parseInt($("#fga-archive-year > li").size(), 10);
		if(pos + li_count >= kol) {
			pos = kol - li_count;
			$(this).attr("id", pos + "");
		}
		else {
			$(this).attr("id", (pos + li_count) + "");
		}
		
		$("a.move-left").attr("id", (pos - li_count) + "");
		$("#fga-panel").scrollTo("li:eq(" + pos + ")", 800 );
		return false;	
	});
	$("a.move-left").click(function() {
		var li_count = 21;
		var pos = parseInt($(this).attr("id"), 10);
		
		$("#fga-panel").scrollTo("li:eq(" + pos + ")", 800 );
		if(pos - li_count < 0) {
			pos = 0;
			$(this).attr("id", "0");
			$("a.move-right").attr("id", li_count + "");
		}
		else {
			$(this).attr("id", (pos - li_count) + "");
			$("a.move-right").attr("id", pos + "");
		}
		
		return false;	
	});
	/*-- gallery --*/
});
