$(document).ready(function(){
	
	$("body").addClass("has-js");
	$("img[src$=png]").pngfix();
	
	// target blank to all rel=external
	$("a[rel$=external]").attr('target','_blank');

	//Start : commented this line for fixing UI issue in subscription checkout page,By NuWare ODC
	// add borders to boxes
	//$("div.box-border").boxborder();
	//End 
	
	// adding tabs and carousel
	if(jQuery.ui) {
	
		jQuery('#nutrisystem-day > ul').tabs();
		jQuery('#nutrisystem-day-box > ul').tabs();
		jQuery('#plan-features > ul').tabs();
		jQuery('#fresh-groceries > ul').tabs();
		jQuery('div.m12-accordion').accordion({ header: 'div.accord-tab' });
		$("ul.carousel").jcarousel({scroll: 1,wrap: 'both'});
		
	}
	
	
	addLoadEvent(function() {
		$("div.grid").gridalign();
	});	
	
	// align grid twice, because of some IE bugs
	if($.browser.msie){
		$("div.grid").gridalign();
	}
	
	// add round corner to boxes
	$("div.box").boxcorner();
	
	// adding tip overlay
	$("p.tooltip,strong.help").tip();

	// fix for ie flicker css background image
	if($.browser.msie){
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err){}
	}
	
	// logged in lite - landing: add list item anhcor image to list items and h2 
	$(".my-plan-mens-basic ul li, .my-plan ul li, .tips-articles h2").prepend("<img src='/images/global/gray-list-arrow-right.gif' />&nbsp;&nbsp;");
	
	// logged in lite - account updates 
	var accountItemArray = $(".account-updates ul").children('li');
	var itemCount = accountItemArray.length;
	accountItemArray.each(function() {
		$(this).append('')
	});
		// logged in lite - remove accont updates fields
		$(".account-updates ul li a.closeBtn").click(function () {
			$(this).parent().remove();
			itemCount--;
				if(itemCount==0){
					$('div.account-updates').remove();
				}
			return false;
		});
	
	// logged in lite - add breadcrumbs list bullet and keep last item link color gray
	$("#breadcrumbs ul li:last-child").addClass('last');
	$("#breadcrumbs ul li a").addClass('bullet-right');
	$("#breadcrumbs ul li:last-child > a").removeClass('bullet-right');
	
	// empty input field onclick 
	
	$("#lbs").focus(function() {
		if( this.value == this.defaultValue ) {
			this.value = "";
		}
	}).blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
		}
	});

});

// onload window event
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

