/*http://richardhulse.blogspot.com/2008/11/equal-height-columns-with-jquery.html*/
jQuery.fn.equalHeights=function(){var maxHeight=0;this.each(function(){if(this.offsetHeight>maxHeight){maxHeight=this.offsetHeight;}});this.each(function(){$(this).height(maxHeight+"px");if(this.offsetHeight>maxHeight){$(this).height((maxHeight-(this.offsetHeight-maxHeight))+"px");}});};

/*http://www.codeasily.com/jquery/multi-column-list-with-jquery*/  
jQuery.fn.makeacolumnlists=function(settings){settings=jQuery.extend({cols:2,colWidth:0,equalHeight:false,startN:1},settings);if(jQuery('> li',this)){this.each(function(y){var y=jQuery('.li_container').size(),height=0,maxHeight=0,t=jQuery(this),classN=t.attr('class'),listsize=jQuery('> li',this).size(),percol=Math.ceil(listsize/settings.cols),contW=t.width(),bl=(isNaN(parseInt(t.css('borderLeftWidth'),10))?0:parseInt(t.css('borderLeftWidth'),10)),br=(isNaN(parseInt(t.css('borderRightWidth'),10))?0:parseInt(t.css('borderRightWidth'),10)),pl=parseInt(t.css('paddingLeft'),10),pr=parseInt(t.css('paddingRight'),10),ml=parseInt(t.css('marginLeft'),10),mr=parseInt(t.css('marginRight'),10),col_Width=Math.floor((contW-(settings.cols-1)*(bl+br+pl+pr+ml+mr))/settings.cols);if(settings.colWidth){col_Width=settings.colWidth;}
var colnum=1,percol2=percol;jQuery(this).addClass('li_cont1').wrap('<div id="li_container'+(++y)+'" class="li_container"></div>');for(var i=0;i<=listsize;i++){if(i>=percol2){percol2+=percol;colnum++;}
var eq=jQuery('> li:eq('+i+')',this);eq.addClass('li_col'+colnum);if(jQuery(this).is('ol')){eq.attr('value',''+(i+settings.startN))+'';}}
jQuery(this).css({cssFloat:'left',width:''+col_Width+'px'});for(colnum=2;colnum<=settings.cols;colnum++){if(jQuery(this).is('ol')){jQuery('li.li_col'+colnum,this).appendTo('#li_container'+y).wrapAll('<ol class="li_cont'+colnum+' '+classN+'" style="float:left; width: '+col_Width+'px;"></ol>');}else{jQuery('li.li_col'+colnum,this).appendTo('#li_container'+y).wrapAll('<ul class="li_cont'+colnum+' '+classN+'" style="float:left; width: '+col_Width+'px;"></ul>');}}
if(settings.equalHeight=='li'){for(colnum=1;colnum<=settings.cols;colnum++){jQuery('#li_container'+y+' li').each(function(){var e=jQuery(this);var border_top=(isNaN(parseInt(e.css('borderTopWidth'),10))?0:parseInt(e.css('borderTopWidth'),10));var border_bottom=(isNaN(parseInt(e.css('borderBottomWidth'),10))?0:parseInt(e.css('borderBottomWidth'),10));height=e.height()+parseInt(e.css('paddingTop'),10)+parseInt(e.css('paddingBottom'),10)+border_top+border_bottom;maxHeight=(height>maxHeight)?height:maxHeight;});}
for(colnum=1;colnum<=settings.cols;colnum++){var eh=jQuery('#li_container'+y+' li');var border_top=(isNaN(parseInt(eh.css('borderTopWidth'),10))?0:parseInt(eh.css('borderTopWidth'),10));var border_bottom=(isNaN(parseInt(eh.css('borderBottomWidth'),10))?0:parseInt(eh.css('borderBottomWidth'),10));mh=maxHeight-(parseInt(eh.css('paddingTop'),10)+parseInt(eh.css('paddingBottom'),10)+border_top+border_bottom);eh.height(mh);}}else
if(settings.equalHeight=='ul'||settings.equalHeight=='ol'){for(colnum=1;colnum<=settings.cols;colnum++){jQuery('#li_container'+y+' .li_cont'+colnum).each(function(){var e=jQuery(this);var border_top=(isNaN(parseInt(e.css('borderTopWidth'),10))?0:parseInt(e.css('borderTopWidth'),10));var border_bottom=(isNaN(parseInt(e.css('borderBottomWidth'),10))?0:parseInt(e.css('borderBottomWidth'),10));height=e.height()+parseInt(e.css('paddingTop'),10)+parseInt(e.css('paddingBottom'),10)+border_top+border_bottom;maxHeight=(height>maxHeight)?height:maxHeight;});}
for(colnum=1;colnum<=settings.cols;colnum++){var eh=jQuery('#li_container'+y+' .li_cont'+colnum);var border_top=(isNaN(parseInt(eh.css('borderTopWidth'),10))?0:parseInt(eh.css('borderTopWidth'),10));var border_bottom=(isNaN(parseInt(eh.css('borderBottomWidth'),10))?0:parseInt(eh.css('borderBottomWidth'),10));mh=maxHeight-(parseInt(eh.css('paddingTop'),10)+parseInt(eh.css('paddingBottom'),10)+border_top+border_bottom);eh.height(mh);}}
jQuery('#li_container'+y).append('<div style="clear:both; overflow:hidden; height:0px;"></div>');});}}
jQuery.fn.uncolumnlists=function(){jQuery('.li_cont1').each(function(i){var onecolSize=jQuery('#li_container'+(++i)+' .li_cont1 > li').size();if(jQuery('#li_container'+i+' .li_cont1').is('ul')){jQuery('#li_container'+i+' > ul > li').appendTo('#li_container'+i+' ul:first');for(var j=1;j<=onecolSize;j++){jQuery('#li_container'+i+' ul:first li').removeAttr('class').removeAttr('style');}
jQuery('#li_container'+i+' ul:first').removeAttr('style').removeClass('li_cont1').insertBefore('#li_container'+i);}else{jQuery('#li_container'+i+' > ol > li').appendTo('#li_container'+i+' ol:first');for(var j=1;j<=onecolSize;j++){jQuery('#li_container'+i+' ol:first li').removeAttr('class').removeAttr('style');}
jQuery('#li_container'+i+' ol:first').removeAttr('style').removeClass('li_cont1').insertBefore('#li_container'+i);}
jQuery('#li_container'+i).remove();});}


$(document).ready(function() {
  /**
   * On the index page, ensure that the article boxes are equal heights
   */
	$("#articles div").equalHeights();  

  /**
   * On the resource center page, break up the article lists into two columns
   */
  $(".resourcecenter #main ul").makeacolumnlists({cols:2,colWidth:265,equalHeight:false,startN:1});
  
	/**
	 * Welcome page enhancements
	 */
	if ($("#cr_product").length && $("#id_product").length) { 
	  /*
	  The following bit of code is used to position the three buttons.
		NOTE code only works correctly when #id_product is shorter than #cr_product.

		The following process is being used to line up the buttons
		  - make the three columns (with buttons) of equal height
		  - position the buttons absolutely at the bottom of the column
		  - tweak the height of #id_product to compensate for the "important" message at the bottom of #cr_product.
		*/
	
		/*make the "getting started" and "logging in" columns equal height*/
	  $("#cr_product .group div").equalHeights();
		/*set the columns, #cr_product and #id_product, to an equal height*/
	  $(".panel").equalHeights();

		/*Set up css styles.*/
		/*apply position relative in order to position elements absolutely within it*/
		$("#cr_product .group div").css('position','relative');
		$("#id_product").css('position','relative');	
		/*position the buttons to the bottom of the column*/	
		$('.product_btn').css({ bottom:"0", position:"absolute" });
	
		/*tweak #id_product's height.*/
		/*get the height of #id_product*/
		var id_product_column = $("#id_product").height();
		/*get the height of the "important" message at the bottom of #cr_product.*/
		var important_msg_height = $("#cr_product p.important").outerHeight(true);
	  /*subtract the height of the last paragraph from the height of the column*/
		newheight = id_product_column - important_msg_height;
		/*apply the new height*/
	  $("#id_product").css("height", newheight);
	}
    
  /**
   * Add print link
   */ 
	$('ul#page_actions').prepend('<li class="print"><a href="#print">Print</a></li>');
	$('ul#page_actions li.print a').click(function(){ window.print(); return false; });
	
	/**
	 * bookmark me link.
	 */
	$("#rememberme").append('<a href="#">Bookmark this page</a>');
	$("#rememberme a").click(function(){ bookmark(location.href, "Credit Score Express login"); return false; });

  
});

/* legacy functions */
function shownewwin(windowURL, windowName, windowFeatures) {
	var newWindow = window.open(windowURL, windowName, windowFeatures);
	newWindow.focus(); 
	return;
}

function SubmitPopUpFormUrl(url) {
	var formAction = document.forms[0].action;
	var formTarget = document.forms[0].target;
	document.forms[0].action = url;
	document.forms[0].target = '_blank';
	document.forms[0].submit();
	document.forms[0].action = formAction;
	document.forms[0].target = formTarget;
}

function bookmark(url, description) {
 netscape="Please press CTRL+D (if you are using Windows) or APPLE+D (if you are on a Mac) to add a bookmark to creditscoreexpress.com."
 if (navigator.appName=='Microsoft Internet Explorer') {
 window.external.AddFavorite(url, description);
 }
 else if (navigator.appName!='Microsoft Internet Explorer') {
 alert(netscape);
 }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length){d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
  if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
