function page(pageNum) {
    $("#Page").val(pageNum);
    $("form[id='search-form']").submit();
}

function SearchClearText() {
	if (document.frm.Keywords.value == "Търси..." || document.frm.Keywords.value == "Search...") {
		document.frm.Keywords.value = ""
		document.frm.Keywords.style.color = "#555555";
		document.frm.Keywords.style.fontStyle = "normal";
	}	
}

function SearchRestoreText() {
	if (document.frm.Keywords.value == "") {
		if((window.document.URL).indexOf('/bg') >= 0) document.frm.Keywords.value = "Търси..."
		else document.frm.Keywords.value = "Search..."
		
		document.frm.Keywords.style.color = "";
		document.frm.Keywords.style.fontStyle = "";
	}	
}

function onLoad() {

    if ((window.document.URL).indexOf('/bg') >= 0) document.frm.Keywords.value = "Търси..."
	else document.frm.Keywords.value = "Search..."
	document.frm.Keywords.onfocus = SearchClearText;
	document.frm.Keywords.onblur = SearchRestoreText;
	for (var i = 0; i < document.getElementById("footer-menu").getElementsByTagName("a").length; i++) {
		var tmp = document.getElementById("footer-menu").getElementsByTagName("a")[i];
		tmp.style.backgroundImage = "url(/images/footer/footer-a-hover.jpg)";
	}
	
	//populateMenu($("#submenu").parent(), 1);

}

$(document).ready(function() { onLoad(); });

$(function(){
		   
	//footer menu animation
	$('#footer-menu a')
		.css ( {backgroundPosition: "15px -50px"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(15px 0px)"}, {duration:700})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(15px -50px)"}, {duration:700})
		}) 
	
});
/*
function gallery_viewer(product_id) {
	alert("I'm in!");
	window.location = "gallery.html";
	$('#' + product_id).css('display','block').fadeIn(1000);
	$('#' + product_id + ' .gallery_demo_unstyled').addClass('gallery_demo');
	$('#' + product_id + ' .gallery_demo').galleria({
			history   : true, // activates the history object for bookmarking, back-button etc.
			clickNext : true, // helper for making the image clickable
			insert    : '#main_image', // the containing selector for our main image
			onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
				
				// fade in the image & caption
				image.css('display','none').fadeIn(1000);
				caption.css('display','none').fadeIn(1000);
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// fade out inactive thumbnail
				_li.siblings().children('img.selected').fadeTo(500,0.3);
				
				// fade in active thumbnail
				thumb.fadeTo('fast',1).addClass('selected');
				
				// add a title for the clickable image
				image.attr('title','Next image >>');
			},
			onThumb : function(thumb) { // thumbnail effects goes here
				
				// fetch the thumbnail container
				var _li = thumb.parents('li');
				
				// if thumbnail is active, fade all the way.
				var _fadeTo = _li.is('.active') ? '1' : '0.3';
				
				// fade in the thumbnail when finnished loading
				thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
				
				// hover effects
				thumb.hover(
					function() { thumb.fadeTo('fast',1); },
					function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
				)
			}
		});
	}


// Prepares a link as menu item
function toMenuItem(a_link, a_level) {
	
	// Item level:
	a_link.level = a_level;
	
	// Save link and make it empty:
	a_link.link = $(a_link).attr("href");
	$(a_link).attr("href", "javascript:;");
	
	// Checks if menu item has submenu:
	a_link.hasSubmenu = function() {
		return $(this).parent().has("ul");
		};
	
	// Checks if submenu is expanded:
	a_link.isExpanded = function() {
		
		if (this.hasSubmenu()) {
			 return !($(this).parent().children("ul").css("display") == "none");
			}
			
		return true;
		
		};
		
	// Expands submenu:
	a_link.expand = function() {
		$(this).parent().children("ul").css("display", "block");
		$(this).parent().addClass("current");
		};
		
	// Collapses submenu:
	a_link.collapse = function() {
		$(this).parent().children("ul").css("display", "none");
		$(this).parent().removeClass("current");
		}
	
	// On click action:
	a_link.onclick = function() {
		
		if (this.hasSubmenu() && !this.isExpanded()) {
			
			for (var j = 0; j < document.menuItems.length; j++) {
				if (document.menuItems[j].level >= this.level) {
					document.menuItems[j].collapse();
					}				
				}
			
			this.expand();
			
			}
		else {
			window.location.href = this.link;
			}
		};
	
	}

// Populates and activates menu:
function populateMenu(a_parent, a_level) {
	
	if (!document.menuItems) {
		document.menuItems = new Array();
		}	
	
	$(a_parent).children("ul").children("li").children("a").each(function(index) {		
		toMenuItem(this, a_level);		
		document.menuItems[document.menuItems.length] = this;
		populateMenu($(this).parent(), a_level + 1);
		});
	
	}*/
