var userAgent = navigator.userAgent.toLowerCase();
 
// Figure out what browser is being used
jQuery.browser = {
	version: (userAgent.match( /.+(?:rv|it|ra|ie|me)[\/: ]([\d.]+)/ ) || [])[1],
	chrome: /chrome/.test( userAgent ),
	safari: /webkit/.test( userAgent ) && !/chrome/.test( userAgent ),
	opera: /opera/.test( userAgent ),
	msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
	mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};

//Pathman Begin 
var cnt =0;
var maxcnt = 0;
var cats = new Array(10);
var stop = 0;
var ad_present = 0;

window.onload = function()
{
	var location1 = '' + document.location;
	// if (location1.search(/index/i) > -1 || location1[location1.length-1] == '/') {
	if (location1.search(/index/i) > -1 || location1.substring(location1.length-1, location1.length) == '/') {
		//var all = document.getElementsByClassName("mainajx");
		//var all = document.all['ajxcats'];
		var all = document.getElementsByName("ajxcats");
		for (var i=0;i<all.length;i++) {
			cats[i]= all[i].getAttribute('rel');
			maxcnt = i; // to store the count of the categories
		}
		//alert('cats0 ' + cats[2]);
		if(ad_present == 1)
		{
			displayCategory( '/specialad.html' + escape( '' ), escape( 'specialad' ) );
			var c = window.setTimeout("doRotate()", 10000);
		}
		else
		{
			doRotate();
		}
	}
};

function doRotate()
{
	if(cnt==maxcnt)
		cnt = 0; //Reset count
	else
		cnt = cnt + 1;  // Go to next category
		
	category_to_display = cats[cnt];
	displayCategory( '/topfive/params/category/' + escape( cats[cnt] ), escape( cats[cnt] ) );
	if(stop==0)
		var c = window.setTimeout("doRotate()", 10000);
}
//Pathman End

if(!Array.indexOf){
	Array.prototype.indexOf = function(obj){
		for(var i=0; i<this.length; i++){
			if(this[i]==obj){
				return i;
			}
		}
		return -1;
	}
}

var category_to_display = 0;
var product_to_display  = 0;
var loading_uris		= [];
var current_mouse_over = 0;
var buycom_ajax = new Array();
var current_buycom_ajax = '';

$( document ).ready( function()
{

	// countdown
	var date = new Date();
	var	countdown = new Date(date.getFullYear(),date.getMonth(),date.getDate() + 1 );
	$("#countdown div").countdown({until: countdown,timezone: -6,compact:true,format: 'HMS',timeSeparator:'',layout: '<span id="hour">{hnn}</span><span id="min">{mnn}</span><span id="sec">{snn}</span>',onExpiry: function(){location.reload();}});
		
	$( '#wrapper' ).before( '<div id="compare"></div>' );
	$( '#wrapper' ).after( '<div id="loading_cursor" style="padding: 2px; background: #FFF; border: 1px solid #CCC; display: none; position: absolute; z-index: 99999; top: 0; left: 0; width: auto;">Loading... Please wait...</div>' );
	
	$( '#ajax_cache' ).hide();
	
	$( '#left .box h2' ).after( $( '#filters' ) );
	
	$( '#header' ).append( $( '.top_crumbs' ) );

	$( '#header' ).append( $( '.browse_category' ) );
	
	$( '#header' ).append( $( '.category_description' ) );
	
	$( "#nav td" ).mouseover( function() {
		$( this ).addClass( 'hover' );
	} );
	$( "#nav td" ).mouseout( function() {
		$( this ).removeClass( 'hover' );
	} );
	
	$( "#main_categories > li" ).mouseover( function( evt ) {
		var e=(evt)?evt:window.event;
		if (window.event) {
			e.cancelBubble=true;
		} else {
			e.cancelBubble = true;
			e.stopPropagation();
		}
		$( "#main_categories > li.whatshot" ).removeClass( 'hover' );
		$( this ).addClass( 'hover' );
	} );
	$( "#main_categories > li" ).mouseout( function( evt ) {
		var e=(evt)?evt:window.event;
		if (window.event) {
			e.cancelBubble=true;
		} else {
			e.cancelBubble = true;
			e.stopPropagation();
		}
		$( this ).removeClass( 'hover' );
	} );
	
	$( "#main_categories" ).mouseout( function( evt ) {
		var e=(evt)?evt:window.event;
		if (window.event) {
			e.cancelBubble=true;
		} else {
			e.cancelBubble = true;
			e.stopPropagation();
		}
		$( '#main_categories > li.whatshot' ).addClass( 'hover' );
	});
	
	var i = 0;
	$( '#nav td a' ).each( function() {
		var rel = $( this ).attr( 'rel' );
		if( rel && rel == selected_microsite )
		{
			if( selected_microsite == 'home' )
			{
				$( this ).parent().parent().addClass( 'active' );
			}
			else
			{
				$( this ).parent().addClass( 'active' );
			}
			if( i )
			{
				$( '#nav td:eq(' + ( i - 1 )  + ')' ).addClass( 'previous' );
			}
		}
		if( rel == 'home' )
		{
			i++
		}
		else
		{
			if( $( this ).parent().get( 0 ).tagName == 'TD' )
			{
				i++;
			}
		}
	} );
	
	$( '#hot_categories .ajax_quick .main_photo' ).before( $( '#main_photo' ) );
	
	showRandomBrands();
	showRandomStores();
	
	$( '.shop_by_brand td.left' ).click( function()
	{
		var parent = $( this ).parent().parent();
		var box_type = $( 'td.brands', parent ).attr( 'rel' );
		var how_many = 5;
		switch( box_type )
		{
			case 'left_type':
				how_many = 3;
				break;
			case 'right_type':
				how_many = 16;
				break;
			case 'center_type':
				how_many = 4;
				break;
		}
		randomBrands( how_many, $( 'td.brands', parent ), $( 'td.brands', parent ).attr( 'rel' ) );
	} );
	$( '.shop_by_brand td.right' ).click( function()
	{
		var parent = $( this ).parent().parent();
		var box_type = $( 'td.brands', parent ).attr( 'rel' );
		var how_many = 5;
		switch( box_type )
		{
			case 'left_type':
				how_many = 3;
				break;
			case 'right_type':
				how_many = 16;
				break;
			case 'center_type':
				how_many = 4;
				break;
		}
		randomBrands( how_many, $( 'td.brands', parent ), $( 'td.brands', parent ).attr( 'rel' ) );
	} );
	
	$( '.shop_by_store td.left' ).click( function()
	{
		var parent = $( this ).parent().parent();
		var box_type = $( 'td.brands', parent ).attr( 'rel' );
		var how_many = 5;
		switch( box_type )
		{
			case 'left_type':
				how_many = 3;
				break;
			case 'right_type':
				how_many = 16;
				break;
			case 'center_type':
				how_many = 4;
				break;
		}
		randomStores( how_many, $( 'td.brands', parent ), $( 'td.brands', parent ).attr( 'rel' ) );
	} );
	$( '.shop_by_store td.right' ).click( function()
	{
		var parent = $( this ).parent().parent();
		var box_type = $( 'td.brands', parent ).attr( 'rel' );
		var how_many = 5;
		switch( box_type )
		{
			case 'left_type':
				how_many = 3;
				break;
			case 'right_type':
				how_many = 16;
				break;
			case 'center_type':
				how_many = 4;
				break;
		}
		randomStores( how_many, $( 'td.brands', parent ), $( 'td.brands', parent ).attr( 'rel' ) );
	} );
	
	$( '.footer_newsletter #subscriber_name' ).focus( function() {
		if( $( this ).val() == 'first name'  )
		{
			$( this ).val( '' );
		}
	} );
	$( '.footer_newsletter #subscriber_name' ).blur( function() {
		if( $( this ).val() == '' )
		{
			$( this ).val( 'first name' );
		}
	} );
	$( '.footer_newsletter #subscriber_email' ).focus( function() {
		if( $( this ).val() == 'your email address'  )
		{
			$( this ).val( '' );
		}
	} );
	$( '.footer_newsletter #subscriber_email' ).blur( function() {
		if( $( this ).val() == '' )
		{
			$( this ).val( 'your email address' );
		}
	} );
	
	$("#inputString").autocomplete("/search/suggestion", { minChars:2 });
	
	/* AJX */
	
	$( '#hot_categories .mainajx' ).bind( 'mouseover', function( e )
	{
		if( ! e.target )
		{
			return;
		}
		
		var el = $( e.target );	
		
		if( el.is( 'span' ) &&
			el.parent().is( '.mainajx' ) )
		{
			el = el.parent();
		}
		if( el.is( 'img' ) &&
		el.parent().parent().is( '.mainajx' ) )
		{
			el = el.parent().parent();
		}
		if( el.is( '.mainajx' ) )
		{
			if( category_to_display == el.attr( 'rel' ) )
			{
				return;
			}
			
			category_to_display = el.attr( 'rel' );
			displayCategory( '/topfive/params/category/' + escape( el.attr( 'rel' ) ), escape( el.attr( 'rel' ) ) );
			stop =1;
			return;
		}
		
		if( el.is( 'span' ) &&
			el.parent().is( '.secajx' ) )
		{
			el = el.parent();
		}
		if( el.is( 'img' ) &&
		el.parent().is( '.secajx' ) )
		{
			el = el.parent();
		}
		if( el.is( '.secajx' ) )
		{
			if( product_to_display == el.attr( 'rel' ) )
			{
				return;
			}
			
			product_to_display = el.attr( 'rel' );
			displayProduct( '/product/quick/params/id/' + escape( product_to_display ), escape( product_to_display ) );
			return;
		}
	} );
	
	if( $( '#mainSearch' ) ) 
	{
//		$( '#mainSearch' ).focus();
	}
	
	var browser_version = $.browser.version

	if( ! $.browser.msie  )
	{
		$( '#nav td.items' ).each( function() {
			var left = $( this ).get(0).offsetLeft;
			if( $.browser.chrome )
			{
				left += 280;
			}
			$( 'ul', this ).css( "left", left + "px" );
		} );
	}
	else
	{
		if( browser_version.substr( 0, 2 ) == "8." )
		{
			$( '#nav td.items' ).each( function() {
				var left = $( this ).get(0).offsetLeft;
				left += 425;
				$( 'ul', this ).css( "left", left + "px" );
				$( 'ul', this ).css( "top", "55px" );
			} );
		}
	}

	$( '#top_nav .feedback' ).click( function() {
		window.open( "/message/suggestion", "", "width=970,height=310,scrollbars=yes" );
		return false;
	} );
	
	$( '#top_nav .tell_friend' ).click( function() {
		window.open( "/message/friend", "", "width=970,height=250,scrollbars=yes" );
		return false;
	} );
	
	formAjaxSubmit();
	
	$( '#buy_ajax_table .over_ajax' ).mouseover( function()
	{
		var el = $( this );
		var show_content = el.attr( 'rel' );
		if( current_buycom_ajax != show_content )
		{
			if( buycom_ajax[show_content] == undefined )
			{
				$.get( '/topfive/category/params/id/' + show_content + '', function( html )
				{
					buycom_ajax[show_content] = html;
					$( '#buycom_ajax_content' ).html( buycom_ajax[show_content] );
				} );
			}
			else
			{
				$( '#buycom_ajax_content' ).html( buycom_ajax[show_content] );
			}
			current_buycom_ajax = show_content;
		}
		return;
	} );
	
});

function showRandomBrands()
{
	$( '.shop_by_brand table tr td.brands' ).each( function() {
		
		var box_type = $( this ).attr( 'rel' );
		switch( box_type )
		{
			case 'left_type':
				randomBrands( 3, $( this ), box_type );
				break;
			case 'right_type':
				randomBrands( 16, $( this ), box_type );
				break;
			case 'center_type':
				randomBrands( 4, $( this ), box_type );
				break;
		}
		
	} );
	setTimeout( 'showRandomBrands()', 7000 );
}

function showRandomStores()
{
	$( '.shop_by_store table tr td.brands' ).each( function() {
		
		var box_type = $( this ).attr( 'rel' );
		switch( box_type )
		{
			case 'left_type':
				randomStores( 3, $( this ), box_type );
				break;
			case 'right_type':
				randomStores( 12, $( this ), box_type );
				break;
			case 'center_type':
				randomStores( 4, $( this ), box_type );
				break;
		}
		
	} );
	setTimeout( 'showRandomStores()', 7000 );
}

function formAjaxSubmit()
{
	var form_submit_options = { 
		target:		'#suggestion_box_div',   // target element(s) to be updated with server response 
		beforeSubmit:  showRequest,  // pre-submit callback 
		success:	   showResponse  // post-submit callback 
	}; 
 
	// bind form using 'ajaxForm' 
	$('#suggestion_box').ajaxForm(form_submit_options);
}

// pre-submit callback 
function showRequest(formData, jqForm, options) { 
	// formData is an array; here we use $.param to convert it to a string to display it 
	// but the form plugin does this for you automatically when it submits the data 
	var queryString = $.param(formData); 
 
	// jqForm is a jQuery object encapsulating the form element.  To access the 
	// DOM element for the form do this: 
	// var formElement = jqForm[0]; 
 
   // alert('About to submit: \n\n' + queryString); 
 $( '#loading_form_ajax' ).show();
	// here we could return false to prevent the form from being submitted; 
	// returning anything other than false will allow the form submit to continue 
	return true; 
} 
 
// post-submit callback 
function showResponse(responseText, statusText)  { 
	// for normal html responses, the first argument to the success callback 
	// is the XMLHttpRequest object's responseText property 
 
	// if the ajaxForm method was passed an Options Object with the dataType 
	// property set to 'xml' then the first argument to the success callback 
	// is the XMLHttpRequest object's responseXML property 
 
	// if the ajaxForm method was passed an Options Object with the dataType 
	// property set to 'json' then the first argument to the success callback 
	// is the json data object returned by the server 
 
   // alert('status: ' + statusText + '\n\nresponseText: \n' + responseText + 
	 //   '\n\nThe output div should have already been updated with the responseText.'); 
	 $( '#loading_form_ajax' ).hide();
	formAjaxSubmit();
}

function redirectTO( url )
{
	document.location=url;
}

function randomBrands( how_many, target, type )
{
	$.get( '/brands/random/params/total/' + how_many + '/type/' + type, function( abc ) { $( 'div', target ).hide().html( abc ).fadeIn() } );
}

function randomStores( how_many, target, type )
{
	$.get( '/brands/stores/params/total/' + how_many + '/type/' + type, function( abc ) { $( 'div', target ).hide().html( abc ).fadeIn() } );
}

function removeSomeClass()
{
	$( '.secajx' ).removeClass( 'active' );
}

/* --- */

function displayWhenReady( id, type )
{
	if( type == 'category' )
	{
		if( ( category_to_display > 0 ) &&
			( category_to_display != id ) )
		{
			return;
		}
		
		var elem = '.ajax_quick';
	}
	else
	{
		if( ( product_to_display > 0 ) &&
			( product_to_display != id ) )
		{
			return;
		}
		
		var elem = '.ajax_quick .quick_product';
	}
	
	$( elem ).html( '' );
	
	$( '#ajx' + id ).clone().appendTo( elem );
	
	if( type == 'category' )
	{
		var firstprod = $( '#ajx' + id + ' a.secajx:first' );
		if( firstprod.length )
		{
			product_to_display = firstprod.attr( 'rel' );
			var category_name = firstprod.attr( 'name' );
			displayProduct( '/product/quick/params/id/' + escape( product_to_display ) + '?c=' + escape( category_name), escape( product_to_display ) );
		}
	}
}

function displayCategory( uri, id )
{
	
	$( '.ajax_quick' ).html( '' );
	
	if( loading_uris.indexOf( id ) > -1 )
	{
		return;
	}

	if( $( '#ajx' + id ).length )
	{
		displayWhenReady( id, 'category' );
		refreshBind();
	}
	else
	{
		loading_uris.push( id );

		$.get( uri, function( html )
		{
			loading_uris.splice( loading_uris.indexOf( id ), 1 );
			
			$( '#ajax_cache' ).append( '<div id="ajx' + id + '" class="something">' + html + '</div>' );
			displayWhenReady( id, 'category' );
			refreshBind();
		} );
	}
}

function displayProduct( uri, id )
{
	$( '.ajax_quick .quick_product' ).html( '' );
	
	if( loading_uris.indexOf( id ) > -1 )
	{
		return;
	}

	if( $( '#ajx' + id ).length )
	{
		displayWhenReady( id, 'product' );
	}
	else
	{
		loading_uris.push( id );
		
		$.get( uri, function( html )
		{
			loading_uris.splice( loading_uris.indexOf( id ), 1 );
			
			$( '#ajax_cache' ).append( '<div id="ajx' + id + '" class="something">' + html + '</div>' );
			displayWhenReady( id, 'product' );
		} );
	}
}

function refreshBind()
{
	$( '#hot_categories .secajx' ).bind( 'mouseover', function( e )
	{
		if( ! e.target )
		{
			return;
		}
		
		var el = $( e.target );	
		
		if( el.is( 'span' ) &&
			el.parent().is( '.secajx' ) )
		{
			el = el.parent();
		}
		if( el.is( 'img' ) &&
		el.parent().is( '.secajx' ) )
		{
			el = el.parent();
		}
		if( el.is( '.secajx' ) )
		{
			removeSomeClass();
			$( el ).addClass( 'active' );
			if( product_to_display == el.attr( 'rel' ) )
			{
				return;
			}
			var category_name = el.attr( 'name' );
			product_to_display = el.attr( 'rel' );
			displayProduct( '/product/quick/params/id/' + escape( product_to_display ) + '?c=' + escape( category_name ), escape( product_to_display ) );
			return;
		}
	} );	
}

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
	window.sidebar.addPanel(title,url,"");
  } else {
	alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function switchSubMenu(el)
{
	var menu = el.parentNode;
	if (menu.className.search('open') > -1) {
		menu.className = 'filter_name';
	} else {
		menu.className = 'filter_name open';
	}
}

function subMenuMore()
{
	var filters = document.getElementById('filters');
	var list = filters.firstChild.firstChild.childNodes[1].childNodes;
	for (i=0; i<list.length; i++) {
		list[i].className = '';
	}
	list[list.length-1].className = 'hidden';
	filters.firstChild.firstChild.className = 'filter_name open';
}

(function($){function Countdown(){this.regional=[];this.regional['']={labels:['Years','Months','Weeks','Days','Hours','Minutes','Seconds'],labels1:['Year','Month','Week','Day','Hour','Minute','Second'],compactLabels:['y','m','w','d'],timeSeparator:':',isRTL:false};this._defaults={until:null,since:null,timezone:null,serverSync:null,format:'dHMS',layout:'',compact:false,description:'',expiryUrl:'',expiryText:'',alwaysExpire:false,onExpiry:null,onTick:null};$.extend(this._defaults,this.regional[''])}var w='countdown';var Y=0;var O=1;var W=2;var D=3;var H=4;var M=5;var S=6;$.extend(Countdown.prototype,{markerClassName:'hasCountdown',_timer:setInterval(function(){$.countdown._updateTargets()},980),_timerTargets:[],setDefaults:function(a){this._resetExtraLabels(this._defaults,a);extendRemove(this._defaults,a||{})},UTCDate:function(a,b,c,e,f,g,h,i){if(typeof b=='object'&&b.constructor==Date){i=b.getMilliseconds();h=b.getSeconds();g=b.getMinutes();f=b.getHours();e=b.getDate();c=b.getMonth();b=b.getFullYear()}var d=new Date();d.setUTCFullYear(b);d.setUTCDate(1);d.setUTCMonth(c||0);d.setUTCDate(e||1);d.setUTCHours(f||0);d.setUTCMinutes((g||0)-(Math.abs(a)<30?a*60:a));d.setUTCSeconds(h||0);d.setUTCMilliseconds(i||0);return d},_settingsCountdown:function(a,b){if(!b){return $.countdown._defaults}var c=$.data(a,w);return(b=='all'?c.options:c.options[b])},_attachCountdown:function(a,b){var c=$(a);if(c.hasClass(this.markerClassName)){return}c.addClass(this.markerClassName);var d={options:$.extend({},b),_periods:[0,0,0,0,0,0,0]};$.data(a,w,d);this._changeCountdown(a)},_addTarget:function(a){if(!this._hasTarget(a)){this._timerTargets.push(a)}},_hasTarget:function(a){return($.inArray(a,this._timerTargets)>-1)},_removeTarget:function(b){this._timerTargets=$.map(this._timerTargets,function(a){return(a==b?null:a)})},_updateTargets:function(){for(var i=0;i<this._timerTargets.length;i++){this._updateCountdown(this._timerTargets[i])}},_updateCountdown:function(a,b){var c=$(a);b=b||$.data(a,w);if(!b){return}c.html(this._generateHTML(b));c[(this._get(b,'isRTL')?'add':'remove')+'Class']('countdown_rtl');var d=this._get(b,'onTick');if(d){d.apply(a,[b._hold!='lap'?b._periods:this._calculatePeriods(b,b._show,new Date())])}var e=b._hold!='pause'&&(b._since?b._now.getTime()<=b._since.getTime():b._now.getTime()>=b._until.getTime());if(e&&!b._expiring){b._expiring=true;if(this._hasTarget(a)||this._get(b,'alwaysExpire')){this._removeTarget(a);var f=this._get(b,'onExpiry');if(f){f.apply(a,[])}var g=this._get(b,'expiryText');if(g){var h=this._get(b,'layout');b.options.layout=g;this._updateCountdown(a,b);b.options.layout=h}var i=this._get(b,'expiryUrl');if(i){window.location=i}}b._expiring=false}else if(b._hold=='pause'){this._removeTarget(a)}$.data(a,w,b)},_changeCountdown:function(a,b,c){b=b||{};if(typeof b=='string'){var d=b;b={};b[d]=c}var e=$.data(a,w);if(e){this._resetExtraLabels(e.options,b);extendRemove(e.options,b);this._adjustSettings(a,e);$.data(a,w,e);var f=new Date();if((e._since&&e._since<f)||(e._until&&e._until>f)){this._addTarget(a)}this._updateCountdown(a,e)}},_resetExtraLabels:function(a,b){var c=false;for(var n in b){if(n.match(/[Ll]abels/)){c=true;break}}if(c){for(var n in a){if(n.match(/[Ll]abels[0-9]/)){a[n]=null}}}},_adjustSettings:function(a,b){var c=this._get(b,'serverSync');c=(c?c.apply(a,[]):null);var d=new Date();var e=this._get(b,'timezone');e=(e==null?-d.getTimezoneOffset():e);b._since=this._get(b,'since');if(b._since){b._since=this.UTCDate(e,this._determineTime(b._since,null));if(b._since&&c){b._since.setMilliseconds(b._since.getMilliseconds()+d.getTime()-c.getTime())}}b._until=this.UTCDate(e,this._determineTime(this._get(b,'until'),d));if(c){b._until.setMilliseconds(b._until.getMilliseconds()+d.getTime()-c.getTime())}b._show=this._determineShow(b)},_destroyCountdown:function(a){var b=$(a);if(!b.hasClass(this.markerClassName)){return}this._removeTarget(a);b.removeClass(this.markerClassName).empty();$.removeData(a,w)},_pauseCountdown:function(a){this._hold(a,'pause')},_lapCountdown:function(a){this._hold(a,'lap')},_resumeCountdown:function(a){this._hold(a,null)},_hold:function(a,b){var c=$.data(a,w);if(c){if(c._hold=='pause'&&!b){c._periods=c._savePeriods;var d=(c._since?'-':'+');c[c._since?'_since':'_until']=this._determineTime(d+c._periods[0]+'y'+d+c._periods[1]+'o'+d+c._periods[2]+'w'+d+c._periods[3]+'d'+d+c._periods[4]+'h'+d+c._periods[5]+'m'+d+c._periods[6]+'s');this._addTarget(a)}c._hold=b;c._savePeriods=(b=='pause'?c._periods:null);$.data(a,w,c);this._updateCountdown(a,c)}},_getTimesCountdown:function(a){var b=$.data(a,w);return(!b?null:(!b._hold?b._periods:this._calculatePeriods(b,b._show,new Date())))},_get:function(a,b){return(a.options[b]!=null?a.options[b]:$.countdown._defaults[b])},_determineTime:function(k,l){var m=function(a){var b=new Date();b.setTime(b.getTime()+a*1000);return b};var n=function(a){a=a.toLowerCase();var b=new Date();var c=b.getFullYear();var d=b.getMonth();var e=b.getDate();var f=b.getHours();var g=b.getMinutes();var h=b.getSeconds();var i=/([+-]?[0-9]+)\s*(s|m|h|d|w|o|y)?/g;var j=i.exec(a);while(j){switch(j[2]||'s'){case's':h+=parseInt(j[1],10);break;case'm':g+=parseInt(j[1],10);break;case'h':f+=parseInt(j[1],10);break;case'd':e+=parseInt(j[1],10);break;case'w':e+=parseInt(j[1],10)*7;break;case'o':d+=parseInt(j[1],10);e=Math.min(e,$.countdown._getDaysInMonth(c,d));break;case'y':c+=parseInt(j[1],10);e=Math.min(e,$.countdown._getDaysInMonth(c,d));break}j=i.exec(a)}return new Date(c,d,e,f,g,h,0)};var o=(k==null?l:(typeof k=='string'?n(k):(typeof k=='number'?m(k):k)));if(o)o.setMilliseconds(0);return o},_getDaysInMonth:function(a,b){return 32-new Date(a,b,32).getDate()},_generateHTML:function(c){c._periods=periods=(c._hold?c._periods:this._calculatePeriods(c,c._show,new Date()));var d=false;var e=0;for(var f=0;f<c._show.length;f++){d|=(c._show[f]=='?'&&periods[f]>0);c._show[f]=(c._show[f]=='?'&&!d?null:c._show[f]);e+=(c._show[f]?1:0)}var g=this._get(c,'compact');var h=this._get(c,'layout');var i=(g?this._get(c,'compactLabels'):this._get(c,'labels'));var j=this._get(c,'timeSeparator');var k=this._get(c,'description')||'';var l=function(a){var b=$.countdown._get(c,'compactLabels'+periods[a]);return(c._show[a]?periods[a]+(b?b[a]:i[a])+' ':'')};var m=function(a){var b=$.countdown._get(c,'labels'+periods[a]);return(c._show[a]?'<span class="countdown_section"><span class="countdown_amount">'+periods[a]+'</span><br/>'+(b?b[a]:i[a])+'</span>':'')};return(h?this._buildLayout(c,h,g):((g?'<span class="countdown_row countdown_amount'+(c._hold?' countdown_holding':'')+'">'+l(Y)+l(O)+l(W)+l(D)+(c._show[H]?this._minDigits(periods[H],2):'')+(c._show[M]?(c._show[H]?j:'')+this._minDigits(periods[M],2):'')+(c._show[S]?(c._show[H]||c._show[M]?j:'')+this._minDigits(periods[S],2):''):'<span class="countdown_row countdown_show'+e+(c._hold?' countdown_holding':'')+'">'+m(Y)+m(O)+m(W)+m(D)+m(H)+m(M)+m(S))+'</span>'+(k?'<span class="countdown_row countdown_descr">'+k+'</span>':'')))},_buildLayout:function(c,d,e){var f=this._get(c,(e?'compactLabels':'labels'));var g=function(a){return($.countdown._get(c,(e?'compactLabels':'labels')+c._periods[a])||f)[a]};var h=function(a,b){return Math.floor(a/b)%10};var j={desc:this._get(c,'description'),sep:this._get(c,'timeSeparator'),yl:g(Y),yn:c._periods[Y],ynn:this._minDigits(c._periods[Y],2),ynnn:this._minDigits(c._periods[Y],3),y1:h(c._periods[Y],1),y10:h(c._periods[Y],10),y100:h(c._periods[Y],100),y1000:h(c._periods[Y],1000),ol:g(O),on:c._periods[O],onn:this._minDigits(c._periods[O],2),onnn:this._minDigits(c._periods[O],3),o1:h(c._periods[O],1),o10:h(c._periods[O],10),o100:h(c._periods[O],100),o1000:h(c._periods[O],1000),wl:g(W),wn:c._periods[W],wnn:this._minDigits(c._periods[W],2),wnnn:this._minDigits(c._periods[W],3),w1:h(c._periods[W],1),w10:h(c._periods[W],10),w100:h(c._periods[W],100),w1000:h(c._periods[W],1000),dl:g(D),dn:c._periods[D],dnn:this._minDigits(c._periods[D],2),dnnn:this._minDigits(c._periods[D],3),d1:h(c._periods[D],1),d10:h(c._periods[D],10),d100:h(c._periods[D],100),d1000:h(c._periods[D],1000),hl:g(H),hn:c._periods[H],hnn:this._minDigits(c._periods[H],2),hnnn:this._minDigits(c._periods[H],3),h1:h(c._periods[H],1),h10:h(c._periods[H],10),h100:h(c._periods[H],100),h1000:h(c._periods[H],1000),ml:g(M),mn:c._periods[M],mnn:this._minDigits(c._periods[M],2),mnnn:this._minDigits(c._periods[M],3),m1:h(c._periods[M],1),m10:h(c._periods[M],10),m100:h(c._periods[M],100),m1000:h(c._periods[M],1000),sl:g(S),sn:c._periods[S],snn:this._minDigits(c._periods[S],2),snnn:this._minDigits(c._periods[S],3),s1:h(c._periods[S],1),s10:h(c._periods[S],10),s100:h(c._periods[S],100),s1000:h(c._periods[S],1000)};var k=d;for(var i=0;i<7;i++){var l='yowdhms'.charAt(i);var m=new RegExp('\\{'+l+'<\\}(.*)\\{'+l+'>\\}','g');k=k.replace(m,(c._show[i]?'$1':''))}$.each(j,function(n,v){var a=new RegExp('\\{'+n+'\\}','g');k=k.replace(a,v)});return k},_minDigits:function(a,b){a=''+a;if(a.length>=b){return a}a='0000000000'+a;return a.substr(a.length-b)},_determineShow:function(a){var b=this._get(a,'format');var c=[];c[Y]=(b.match('y')?'?':(b.match('Y')?'!':null));c[O]=(b.match('o')?'?':(b.match('O')?'!':null));c[W]=(b.match('w')?'?':(b.match('W')?'!':null));c[D]=(b.match('d')?'?':(b.match('D')?'!':null));c[H]=(b.match('h')?'?':(b.match('H')?'!':null));c[M]=(b.match('m')?'?':(b.match('M')?'!':null));c[S]=(b.match('s')?'?':(b.match('S')?'!':null));return c},_calculatePeriods:function(f,g,h){f._now=h;f._now.setMilliseconds(0);var i=new Date(f._now.getTime());if(f._since){if(h.getTime()<f._since.getTime()){f._now=h=i}else{h=f._since}}else{i.setTime(f._until.getTime());if(h.getTime()>f._until.getTime()){f._now=h=i}}var j=[0,0,0,0,0,0,0];if(g[Y]||g[O]){var k=$.countdown._getDaysInMonth(h.getFullYear(),h.getMonth());var l=$.countdown._getDaysInMonth(i.getFullYear(),i.getMonth());var m=(i.getDate()==h.getDate()||(i.getDate()>=Math.min(k,l)&&h.getDate()>=Math.min(k,l)));var n=function(a){return(a.getHours()*60+a.getMinutes())*60+a.getSeconds()};var o=Math.max(0,(i.getFullYear()-h.getFullYear())*12+i.getMonth()-h.getMonth()+((i.getDate()<h.getDate()&&!m)||(m&&n(i)<n(h))?-1:0));j[Y]=(g[Y]?Math.floor(o/12):0);j[O]=(g[O]?o-j[Y]*12:0);var p=function(a,b,c){var d=(a.getDate()==c);var e=$.countdown._getDaysInMonth(a.getFullYear()+b*j[Y],a.getMonth()+b*j[O]);if(a.getDate()>e){a.setDate(e)}a.setFullYear(a.getFullYear()+b*j[Y]);a.setMonth(a.getMonth()+b*j[O]);if(d){a.setDate(e)}return a};if(f._since){i=p(i,-1,l)}else{h=p(new Date(h.getTime()),+1,k)}}var q=Math.floor((i.getTime()-h.getTime())/1000);var r=function(a,b){j[a]=(g[a]?Math.floor(q/b):0);q-=j[a]*b};r(W,604800);r(D,86400);r(H,3600);r(M,60);r(S,1);if(q>0&&!f._since){var s=[1,12,4.3482,7,24,60,60];var t=S;var u=1;for(var v=S;v>=Y;v--){if(g[v]){if(j[t]>=u){j[t]=0;q=1}if(q>0){j[v]++;q=0;t=v;u=1}}u*=s[v]}}return j}});function extendRemove(a,b){$.extend(a,b);for(var c in b){if(b[c]==null){a[c]=null}}return a}$.fn.countdown=function(a){var b=Array.prototype.slice.call(arguments,1);if(a=='getTimes'||a=='settings'){return $.countdown['_'+a+'Countdown'].apply($.countdown,[this[0]].concat(b))}return this.each(function(){if(typeof a=='string'){$.countdown['_'+a+'Countdown'].apply($.countdown,[this].concat(b))}else{$.countdown._attachCountdown(this,a)}})};$.countdown=new Countdown()})(jQuery);