/* 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;
		}
	});
}

$(document).ready(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 */
	$(".default-value").each(function() {
		$(".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];
				}
			});
		});
	});
	
	/* office dropdown change */
	$("#office").change(function() {
		id = $("#office").val();
		$(".office").hide();
		$("#office_" + id).show();
		
		// change google maps center
		animate(id);
	});
	
	/* image mouse over */
    $(".footer img")
    .mouseover(function() { 
        var src = $(this).attr("src").replace("_bw", "");
        $(this).attr("src", src);
    })
    .mouseout(function() {
        var src = $(this).attr("src").match(/[^\.]+/) + "_bw.png";
        $(this).attr("src", src);
    });
    
    /* menu mouse over */
    $(".menubutton")
    .mouseover(function() {
    	$(this).animate({
    		height: "32px"
    	}, 200);
    })
    .mouseout(function() {
    	if ($(this).attr("class") != "menubutton menubutton_active") {
  		  	$(this).animate({
  		  		height: "26px"
  		  	}, 200);
  		}
    });
    
    /* dropdown menus */
	$("li.item > ol").hide();
	$("li.item").hover(function(){
		$("ol",this).show();
	},function(){
		$("ol",this).hide();
	});
	
	/* left menu mouseovers */
	$(".menu span:not(.active)")
	.mouseover(function() {
		$(this).css("backgroundColor", "white");
		$(this,"a").css("color", "black");
	})
	.mouseout(function() {
		$(this).css("backgroundColor", "black");
		$(this,"a").css("color", "white");
	});
	
	/* home buttons */
	$("#button_next").click(function() {
		if (count < max) {
			count++;
			return BannerChange(count);
		}
		return false;
	});
	$("#button_prev").click(function() {
		if (count > 0) {
			count--;
			return BannerChange(count);
		}
		return false;
	});
});

/* change content on home */
function BannerChange(count) {
	// change background image
	$('#container').css({
		backgroundImage : "url(/img/banner/" + img_array[count] + ")"
	});
	
	// change text boxes
	$('.banner_name')
	.empty()
	.append(name_array[count]);
	
	// change link
	$('#banner_link')
	.empty()
	.append('<a href="' + link_array[count] + '">' + link_name_array[count] + '</a>');
	
	// change link left
	$('#banner_link_left')
	.attr("href", linkleft_array[count]);
	
	$('#banner_left')
	.empty()
	.append(linkleft_name_array[count]);
	
	// change link right
	$('#banner_link_right')
	.attr("href", linkright_array[count]);
	
	$('#banner_right')
	.empty()
	.append(linkright_name_array[count]);
	
	return false;
}
