var firefox = navigator.userAgent.indexOf('Firefox') != -1
var explorer = navigator.userAgent.indexOf('MSIE') != -1
var explorer7 = navigator.userAgent.indexOf('MSIE 7.0') != -1
var netscape = navigator.userAgent.indexOf('Netscape') != -1
var safari = navigator.userAgent.indexOf('Safari') != -1
var opera = navigator.userAgent.indexOf('Opera') != -1
var camino = navigator.userAgent.indexOf('Camino') != -1
var macintosh = navigator.platform.indexOf('Mac') != -1

function correctPNG() {
	for(var i=0; i<document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:block;" + img.style.cssText
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
			var strNewHTML = "<span class=\"pngFix\" " + imgID + imgClass + imgTitle
			+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
			+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
			+ "(src='" + img.src + "', sizingMethod='scale');\"></span>"
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}

if (explorer && !explorer7) {
	window.attachEvent('onload', correctPNG);
}

function switchSubmenu(whichSub){
  $(".menu > ul > li").removeClass("active");
  $(".menu > ul > li").addClass("off");

	if($(whichSub).next(".submenu").hasClass("outOfTheWay")){
		$(whichSub).next(".submenu").removeClass("outOfTheWay");
		$(whichSub).parent().addClass("active").removeClass("off");
	} else {
		$(whichSub).next(".submenu").addClass("outOfTheWay");
	}

	return false;
}

function assignLeftNav(action, which, whichSide){
	if(whichSide == "leftNav"){
		whichID = which.substring(9,11);
	} else {
		whichID = which.substring(8,10);
	}

	return false;
}

function openLeftNavSub(which, whichSide){
	id = $(which).attr('id');
/*
	if(whichSide == "leftNav"){
		whichID = id.substring(9,11);
	} else {
		whichID = id.substring(8,10);
	}

	classOn = whichSide + whichID + "On";

	if($(which).children(".navSub").hasClass("outOfTheWay")){
		$("#" + whichSide + " .navSub").addClass("outOfTheWay");
		$(which).children(".navSub").removeClass("outOfTheWay");

		$("#" + whichSide + " ul").removeClass();
		$("#" + whichSide + " ul").addClass(classOn);
	}else{
		$("#" + whichSide + " .navSub").addClass("outOfTheWay");
		$("#" + whichSide + " ul").removeClass(classOn);
	}
*/
	return false;
}

function openRightNavSub(which){
  parentId = $(which).parent().attr('id');
	id = $(which).attr('id');

  if ($(which).parent().hasClass("On")) {
    $(which).parent().removeClass("On");

  } else {
    $(which).parent().addClass("On");
  }

	return false;
}

function hideKeywords(which, action){
	if(action == "hide"){
		input = $(which).next();
		input.focus();
		$(which).addClass("outOfTheWay");
	} else {
		if($(which).val() == ""){
			$(which).prev().removeClass("outOfTheWay");
		}
	}
	return false;
}


function switchMemberLogin(action){
	if(action == "show"){
		$("#wrapMember").removeClass("outOfTheWay");
		$(".bt_memberLogin").addClass("outOfTheWay");
	} else {
		$("#wrapMember").addClass("outOfTheWay");
		$(".bt_memberLogin").removeClass("outOfTheWay");
	}

}


// Delay
jQuery.fn.delay = function(time,func){
	this.each(function(){ setTimeout(func,time); });
	return this;
};


$(function() {

	// Tell the stylesheet that javascript is enabled for this page
	$('body').removeClass('noJs');

	$(".menu .bt_menu").bind('mouseover', function(){
		$(".submenu").addClass("outOfTheWay");
		switchSubmenu(this);
		return false;
	})

	$(".menu").bind('mouseleave', function(){
		$(".menu li").removeClass("active");
		$(".menu li").removeClass("off");
		$(".submenu").addClass("outOfTheWay");
		return false;
	})

	$(".submenu").bind('mouseleave', function(){
		$(".menu li").removeClass("active");
		$(".menu li").removeClass("off");
		$(".submenu").addClass("outOfTheWay");
		return false;
	})

	$(".nav ul li").has("div.navSub").find("a.navItem").addClass("navItemList").click(function(){
		if ($(this).attr("href") == "#" || ($(this).attr("href") == "#" && $(this).parent().hasClass("Current"))) {
		  openRightNavSub($(this));
		  return false;
		}
	})

	$("div.keywords").click(function(){
		hideKeywords(this, "hide");
		return false;
	})

	$("input").bind("blur", function(){
		hideKeywords(this, "show");
		return false;
	})

	$(".content .col h2:first-child").addClass("first");
	$("#wrapLeftNav h2:first-child").addClass("first");

	$("table.list tr:even:not(:first)").addClass("even");
});
