// combine the following js files into one in order to reduce the number of server requests

// ====== comCorner.js ====== //
var num=1;
function test(){
		$(".exText").show()
		$("#menu").show()
	}
function displayNav(){
	$(".exText").hide()
	$("#menu").hide()
	setTimeout("test()", 5000);

}
function rightDown(){
	if(num%2>0){
		$("#inforcontent").slideDown("slow");
		$(".rightDown").css({background:'url(/images/common/right-nava-up.png) no-repeat'});
	}else{
		$("#inforcontent").slideUp("slow");
		$(".rightDown").css({background:'url(/images/common/right-nava-down.png) no-repeat'});
	}
	num++;
}
var $category;
var $subCategory;
//about all div's corner background
$(document).ready(function() {
		$("#rightNTitle").click(
				function(){
					if(num%2>0){
						$("#inforcontent").slideDown("slow");
						$(".rightDown").css({background:'url(/images/common/right-nava-up.png) no-repeat'});
					}else{
						$("#inforcontent").slideUp("slow");
						$(".rightDown").css({background:'url(/images/common/right-nava-down.png) no-repeat'});
					}
					num++;
				}
		)
		$(".rightDown").click(
				function(){
					if(num%2>0){
						$("#inforcontent").slideDown("slow");
						$(".rightDown").css({background:'url(/images/common/right-nava-up.png) no-repeat'});
					}else{
						$("#inforcontent").slideUp("slow");
						$(".rightDown").css({background:'url(/images/common/right-nava-down.png) no-repeat'});
					}
					num++;
				}
		)
		$("#f li").hover(
					function(e){
						$(this).css("background-color","#69bde2");
					},
					function(e){
						$(this).css("background-color","");
					}
			);

		$(".topNavText").parent().hover(
				/*
			function(e){
				var $th=$(this).find('.topNavText');
				var thread = setTimeout(function() {
					$th.next().html("<img src='/images/common/nav-top-right-close.png'/>");
					$th.prev().html("<img src='/images/common/nav-top-left-close.png'/>");
					$th.css("background-color","#0253a1");
					showSubNavItems($th);

					if($category) {
						if($th.html() != $category.html()){
							hideCategory($category);
						} else {
							if ($category) {
								showCategory($category);
							}
							if ($subCategory) {
								showSubCategory($subCategory);
							}
						}
					}
				}, 300);
			},
			function(e){
				var $th=$(this).find('.topNavText');
				var thread = setTimeout(function() {
					hideCategory($th);

					if ($category) {
						showCategory($category);
					}
					if ($subCategory) {
						showSubCategory($subCategory);
					}
				}, 300);
			}
			*/
				function(e){
					var $th=$(this).find('.topNavText');
					$th.next().html("<img src='/images/common/nav-top-right-close.png'/>");
					$th.prev().html("<img src='/images/common/nav-top-left-close.png'/>");
					$th.css("background-color","#0253a1");
					showSubNavItems($th);

					if($category) {
						if($th.html() != $category.html()){
							hideCategory($category);
						} else {
							if ($category) {
								showCategory($category);
							}
							if ($subCategory) {
								showSubCategory($subCategory);
							}
						}
					}
				},
				function(e){
					var $th=$(this).find('.topNavText');
					hideCategory($th);

					if ($category) {
						showCategory($category);
					}
					if ($subCategory) {
						showSubCategory($subCategory);
					}
				}
			);

		$(".lastInor ul li").hover(function(){
			$(this).css("background-color","#1a9be1")

		},
			function(){
			$(this).css("background-color","")
		}
		);

		$(".babyRInfor ul li").hover(
			function(){
				$(this).css("background-color","#bfd9f0");
			},
			function(){
				$(this).css("background-color","");
			}
		);
		
		//on the money mgt page
		$(".rightToolGuide .rightToolM h3").vAlign();				
			
}); //end document ready function


function showCategory(category) {
	$category = category;
	$category.next().html("<img src='/images/common/nav-top-right-close.png'/>");
	$category.prev().html("<img src='/images/common/nav-top-left-close.png'/>");
	$category.css("background-color","#0253a1");
	showSubNavItems($category);
}

function hideCategory(hideObject) {
	hideObject.next().html("");
	hideObject.prev().html("");
	hideObject.css("background-color","");
//	hideObject.next().next().css("display","none");
//	hideObject.next().next().wait().hide(1, "hide");
	hideObject.next().next().hide();
}

function showSubCategory(subCategory) {
	$subCategory = subCategory;
	showCategory($subCategory.parent().parent().prev().prev());
	$subCategory.find('a').css({color:'white'});
}

function showSubNavItems(subObject) {
//	subObject.next().next().wait().show(1);
	subObject.next().next().show();
	var $subul=subObject.next().next().find('ul:eq(0)').find('li').size();
	var $subli=subObject.next().next().find('ul:eq(0)').find('li');
	var $first=subObject.parent().prev();
	var $last=subObject.parent().next();
	if($first.length<1){
		subObject.next().next().css({left:'-10px',width:'750px'});
	}else if($last.length<1){
		subObject.next().next().css({right:'-35px',width:'660px'});
	}else if($first.prev().length<1){
		subObject.next().next().css({left:'-250px',width:'930px'});
	}else if($last.next().length<1){
		subObject.next().next().css({right:'-130px',width:'520px'});
	}else {
		subObject.next().next().css({left:-(($subul-2)*130+14)/2+"px",width:'600px'});
	}
}

$.fn.wait = function(time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function() {
        var self = this;
        setTimeout(function() {
            $(self).dequeue();
        }, time);
    });
};

// ====== favorites.js ====== //

$(document).ready(function() {
	//404 page populer list
	$(".listInfor").bind("mouseover",function(){
		$(this).css("background-color","#ffffff");
		
	});
	$(".listInfor").bind("mouseout",function(){
		$(this).css("background-color","");
		
	});
	
	$(".listS").bind("mouseover",function(){
		$(this).css("background-color","#ffffff");
		
	});
	$(".listS").bind("mouseout",function(){
		$(this).css("background-color","");
		
	});
	$(".favorListsTop div:eq(1)").bind("click",function(){
		$(".manyMostTop").css("background","url('/images/favorites/infor-9.png') no-repeat");
		$(".manyMostBottom").css("background","url('/images/favorites/infor-10.png') no-repeat");
		$(".favorListsTop").hide();
		$(".favorListsTop2").show();
		$(".commtLists").show();
		$(".favorLists").hide();
		$(".commtPageCh").css("background","url('/images/favorites/infor-11.png') no-repeat");
		
	});
	$(".favorListsTop2 div:eq(0)").bind("click",function(){
		$(".manyMostTop").css("background","url('/images/favorites/infor-3.png')");
		$(".manyMostBottom").css("background","url('/images/favorites/infor-4.png')");
		$(".favorListsTop2").hide();
		$(".favorListsTop").show();
		$(".commtLists").hide();
		$(".favorLists").show();
	});
	$(".listCag").bind("mouseover",function(){
		$(this).css("background-color","#ffffff");
	})
	$(".listCag").bind("mouseout",function(){
		$(this).css("background-color","");
	})
})


// ====== tracking.js ====== //
/*---------------------*/
/*   GA Tracking       */
/*-------------------- */

$(document).ready(function() {

	$('A[rel*="track"]').click( function() {
        trackPage(this.name);
	});
	$('A[rel*="event"]').click( function() {
		var ary = this.name.split("~");
		var section = "";
		var subsection = "";
		var event = "";
		if(ary[0] != undefined)
			section = ary[0];
		if(ary[1] != undefined)
			subsection = ary[1];
		if(ary[2] != undefined)
			event = ary[2];

        trackEvent(section, subsection, event);
	});

});

function trackPage(pageName){
	//alert("Tracking: " + pageName);
	pageTracker._trackPageview(pageName);
}

function trackEvent(section, subsection, event){
	if(section == undefined)
		section = "";
	if(subsection == undefined)
		subsection = "";
	if(event == undefined)
		event = "";

//	alert("Event: " + section + " : " + subsection + " : " + event);
	pageTracker._trackEvent(section, subsection, event);
}

function trackSpotlight(cat){

	// cat param is as follows
	// tidel767
	// src=2409535;type=lives687;cat=lshom895;ord=1;num='+ a + '?

	var url = "http://ad.doubleclick.net/activity;src=2409535;type=lives687;cat=" + cat + ";ord=1";
	//alert("Spotlight: " + url);

	var axel = Math.random()+"";
	var a = axel * 10000000000000;

	var img = document.createElement('img');
	img.src = url + ';num=' + a+"?";
}


// ====== util.js ====== //
/*
Global JS file of utility and helper functions
*/
function openPopup( pageToLoad, winName, width, height, center, scroll, winXpos, winYpos, resize) {

xposition = 0;
xposition = winXpos;
yposition = 0;
yposition = winYpos;
resizable = 0;
resizable = resize;
if ((parseInt(navigator.appVersion) >= 4 ) && (center)) {
	xposition = (screen.width - width) / 2;
	yposition = (screen.height - height) / 2;
}
args = "width=" + width + ","     + "height=" + height + ","
+ "location=0," + "menubar=0,"  + "resizable=" + resizable + "," + "scrollbars=" + scroll + ","
+ "status=0,"   + "titlebar=0," + "toolbar=0," +                   "hotkeys=0,"
+ "screenx=" + xposition + ","  //NN Only
+ "screeny=" + yposition + ","  //NN Only
+ "left=" + xposition + ","     //IE Only
+ "top=" + yposition;           //IE Only

return window.open( pageToLoad,winName,args );
}



jQuery.fn.centerVertically = function(options) {
var pos = {
	sTop : function() {
		return window.pageYOffset || document.documentElement && document.documentElement.scrollTop ||  document.body.scrollTop;
	},

	wHeight : function() {
		return window.innerHeight || document.documentElement && document.documentElement.clientHeight || document.body.clientHeight;
	}
};

return this.each(function(index) {

	if (index == 0) {
		var $this = $(this);
		var elHeight = $this.height();
		var elTop = pos.sTop() + (pos.wHeight() / 2) - (elHeight / 2);

		$this.css({
			position: 'absolute',
			marginTop: '0',
			top: elTop
		});
	}
});
};



function queryString(parameter) {
var loc = location.search.substring(1, location.search.length);
var param_value = false;

var params = loc.split("&");
for (i=0; i<params.length;i++) {
  param_name = params[i].substring(0,params[i].indexOf('='));
  if (param_name == parameter) {
      param_value = params[i].substring(params[i].indexOf('=')+1)
  }
}
if (param_value) {
  return param_value;
}
else {
  return ""; //Here determine return if no parameter is found
}
}

var addthis_config = {
services_compact: 'email, facebook, twitter, digg, myspace,delicious,google,more',
services_exclude: 'print,favorites'
}

function setBandwidthCookie(cname, cvalue) {
$.cookie(cname, cvalue, {path:'/'});
}

$(document).ready(function(){
$("input#searchFile").labelify();
$("input#searchFile2").labelify();

// from common.js.jsp
jQuery.validator.addMethod("alphanumeric", function(value, element) {
	return this.optional(element) || /^[0-9A-Za-z-_ ]+$/i.test(value);
//		return this.optional(element) || /^\w+$/i.test(value);
}, "");

jQuery.validator.addMethod("invalidWords", function(value, element, param) {
	var flag = $.ajax({
		async: false,
		url: "/jquery/remoteValidator.jspx",
		type: "post",
		data: {
			checkType: "invalidWords",
			inputVal: function() {
				return $(param).val();
			}
		}
	}).responseText;
	if (flag == "true") {
		return true;
	} else {
		return false;
	}
}, "");

/**
jQuery.validator.addMethod("requNum", function(value, element) {
	return this.optional(element) || /[a-z][A-Z]\d{1}[a-z][A-Z]|\d{1}[a-z][A-Z]\d{1}|\d{1}[a-z][A-Z]|[a-z][A-Z]\d{1}/i.test(value);
}, "");
**/

jQuery.validator.addMethod("equalToSame", function(value, element, param) {
	var input1 = $(param).val().toLowerCase();
	var input2 = value.toLowerCase();
	return input1 == input2;
});

jQuery.validator.addMethod("unequalTo", function(value, element, param) {
	if ($(param).val() == "") {
		return true;
	}
	var flag = true;
	var displayName = $(param).val().toLowerCase();
	var password = value.toLowerCase();
	if(password.indexOf(displayName) >= 0) {
		flag = false;
	}
	return flag;
});

jQuery.validator.addMethod("unequalToId", function(value, element, param) {
	if ($(param).val() == "") {
		return true;
	}
	var flag = true;
	var logidId = $(param).val().toLowerCase();
	var password = value.toLowerCase();
	if(password.indexOf(logidId) >= 0) {
		flag = false;
	}
	return flag;
});

	//var container = $('div.container');
});

//for vertical align issues:
(function ($) {
$.fn.vAlign = function() {
	return this.each(function(i){
	var ah = $(this).height();
	var ph = $(this).parent().height();
	var mh = (ph - ah) / 2;
	$(this).css('padding-top', mh);
	});
};
})(jQuery);
