/* adds bookmark in browser */
function CreateBookmarkLink(title, url) {
	if (window.sidebar) {
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) {
		window.external.AddFavorite( url, title);
	} else if(window.opera && window.print) {
		return true;
	}
}

/* creates hyperlinks for table rows */
function Goto(page) {
	$("tr.highlight").click(function (event) {
		if ($(event.target).is('td')) {
			document.location.href = page;
		}
	});
}

$(function() {
	/* product tabs */
	$("#tabs").tabs();
	
	/* auto complete the search */
	$("#autocomplete").autocomplete("/api.php", {extraParams:{section:"search"}, maxItemsToShow:20});
	
	/* validate forms */
	$("#validate").validate();
	$.metadata.setType("attr", "validate");
	
	/* input fields with default values */
	$("input.default-value").each(function() {
		$("input.default-value").css("color", '#444444');
			var default_values = new Array();
			$(this).focus(function() {
				if (!default_values[this.id]) {
					default_values[this.id] = this.value;
				}
				if (this.value == default_values[this.id]) {
					this.value = '';
					this.style.color = '#000000';
				}
			$(this).blur(function() {
				if (this.value == '') {
					this.style.color = '#444444';
					this.value = default_values[this.id];
				}
			});
		});
	});
	
	/* home buttons */
	$("#button_next").click(function() {
		BannerChangeStop();
		if (count < max) {
			count++;
			return BannerChange(count);
		}
		return false;
	});
	$("#button_prev").click(function() {
		BannerChangeStop();
		if (count > 0) {
			count--;
			return BannerChange(count);
		}
		return false;
	});
	
	/* click on banner */
	$('#banner').click(function() {
		window.location = link_array[count];
	});
	
	/* automaticly change every few seconds */
	BannerChangeAuto();
});

/* change content on home */
function BannerChange(count) {
	// change background image
	$('#banner').css({
		backgroundImage : "url(/img/banner/" + img_array[count] + ")"
	});
	
	// change link
	$('#banner').attr("rel", count);
	
	return false;
}

change = true;
function BannerChangeAuto() {
	setTimeout(function() {
		if (change) {
			if (count < max) {
				count++;
			} else {
				count = 0;
			}
			BannerChange(count);
			BannerChangeAuto();
		}
	}, 5000);
};

function BannerChangeStop() {
	change = false;
}