/************************************************************************ 

ABOUT MAIN.JS

Main.js will be called for every page within your eStore. 
Each page that exists in SigmaCommerce has a corresponding function that is defined in Main.js.
For example: when the homepage is loaded, page_homepage() will be triggered. 


************************************************************************/
var storepath = '/';

$(document).ready(function() {
	
	/************************************************************************ 
	DO NOT DELETE THE BETWEEN THIS LINE...
	*/
	processPage(PageName);
	$('#contentPart').append('<div style="clear:both;"></div>');
	/* 
	END DO NOT DELETE
	************************************************************************/
	
	all_pages(); // Called for each page request.
}); // End Document Ready

/************************************************************************ 
ALL PAGES
************************************************************************/
function all_pages() {

}


/************************************************************************ 
HOME PAGE 
************************************************************************/
function page_homepage() { 
	//12-30-2011 Code for Countdown to end of shipping Script
	var today = new Date();
	var start = new Date("December 30, 2011 04:08:00");
	var end = new Date("December 31, 2011 23:59:59");
	if(today >= start && today <= end){
		var countDownHtml = '<table id="Table_01" width="970" height="100" border="0" cellpadding="0" cellspacing="0"><tr><td rowspan="2"><img src="/_Images/holiday_free_shipping_2011_01.jpg" width="502" height="100" alt=""></td><td><img src="_Images/holiday_free_shipping_2011_02.jpg" width="468" height="44" alt=""></td></tr><tr><td style="border-right:1px solid #979797; border-bottom:1px solid #979797;"><div id="saleCountdown" style="width:100%; height:auto; margin:0 auto;"><div id="countdown_dashboard"><div class="dash days_dash"><span class="dash_title">days</span><div class="digit">0</div><div class="digit">0</div></div><div class="dash hours_dash"><span class="dash_title">hours</span><div class="digit">0</div><div class="digit">0</div></div><div class="dash minutes_dash"><span class="dash_title">minutes</span><div class="digit">0</div><div class="digit">0</div></div><div class="dash seconds_dash"><span class="dash_title">seconds</span><div class="digit">0</div><div class="digit">0</div></div></div><div style="clear:both;"></div></div></td></tr></table>';
		$('#ad_bottom').html(countDownHtml);
		$('#countdown_dashboard').countDown({
			targetOffset: {
				'day': 		1,
				'month': 	0,
				'year': 	0,
				'hour': 	0,
				'min': 		0,
				'sec': 		0
			}
		});
		$('#countdown_dashboard').stopCountDown();
		$('#countdown_dashboard').setCountDown({
			targetDate: {
				'day': 		31,
				'month': 	12,
				'year': 	2011,
				'hour': 	23,
				'min': 		59,
				'sec': 		59
			}
		});
		$('#countdown_dashboard').startCountDown();
	}
}

/************************************************************************ 
PRODUCT:::STYLE MASTER 
************************************************************************/
function page_stylemasteritem() {
	js_product();
}

/************************************************************************ 
PRODUCT::: CONFIGURABLE KIT PAGE
************************************************************************/
function page_configurablekititem() {

}


/************************************************************************ 
PRODUCT:::PHYSICAL ITEM 
************************************************************************/
function page_physicalitem() {
	js_product();
}

/************************************************************************ 
GENERIC FUNCTIONS FOR PRODUCT PAGES - Stylemaster, Physical
************************************************************************/
function js_product() { 

}

/************************************************************************ 
GROUP::: GROUP LEVEL 2
************************************************************************/
function page_grouplevel2() {
	js_group();	
}

/************************************************************************ 
GROUP::: GROUP LEVEL 1
************************************************************************/
function page_grouplevel1() {
	js_group();	
}

/************************************************************************ 
GENERIC FUNCTIONS FOR BOTH GROUPLEVEL 1, GROUPLEVEL 2 and SUBGROUP RESULTS
************************************************************************/
function js_group() {

	$('.subgroupsitemsblock').each(function() {
		var myHref = $(this).children('.subgroup_text_link').attr("href");
		var myLink = '<div class="viewAllLink"><a href="' + myHref + '">View All</a></div>';		
		$(this).children('.display_subgroup_product_results').html(function(index, oldhtml){
			return oldhtml + myLink;
		});	
	});	
		
}

/************************************************************************ 
ONE PAGE ACCOUNT 
************************************************************************/
function page_onepagecheckout() { 

}

/************************************************************************ 
ONE PAGE ACCOUNT 
************************************************************************/
function page_onepageaccount() {
	
	
}

/************************************************************************ 
REVIEW ORDER PAGE
************************************************************************/
function page_revieworder() { 


}

/************************************************************************ 
VIEW ORDER PAGE
************************************************************************/
function page_vieworder() { 

}

/************************************************************************ 
SHOPPING CART 
************************************************************************/
function page_shoppingcart() { 

}

/************************************************************************ 
SEARCH RESULTS PAGE
************************************************************************/
function page_searchresults() { 


}

/************************************************************************ 
MY ACCOUNT
************************************************************************/
function page_myaccount() { 

}


/************************************************************************ 
CHANGE LOGIN PAGE
************************************************************************/
function page_changelogin() { 


}


/************************************************************************ 
EMAIL OPTIN OPTOUT
************************************************************************/
function page_emailoptinoptout() { 

}


/************************************************************************ 
GIFT CARD BALANCE
************************************************************************/
function page_giftcardbalance() {
		
}


/************************************************************************ 
GIFT CARD ITEM
************************************************************************/
function page_giftcarditem() { 


}

/************************************************************************ 
VIEW ORDER HISTORY
************************************************************************/
function page_vieworderhistory() { 

}

/************************************************************************ 
TRACK RECENT ORDERS PAGE
************************************************************************/
function page_trackrecentorders() { 

		
}

/************************************************************************ 
UPDATE BILLING INFORMATION
************************************************************************/
function page_updatebillinginformation() { 

	
}

/************************************************************************ 
CREDIT BALANCE
************************************************************************/
function page_creditbalances() { 
		

}


/************************************************************************ 
WISH LIST
************************************************************************/
function page_wishlist() {


}

/************************************************************************ 
MANAGE SHIPPING ADDRESSES
************************************************************************/
function page_manageshippingaddresses() { 

}


/************************************************************************ 
MISCELLANEOUS PAGE
************************************************************************/
function page_miscellaneous() {	

}


/************************************************************************ 
SEND TO A FRIEND
************************************************************************/
function page_sendtofriend() {	

}

/************************************************************************ 
ORDER CONFIRMATION PAGE
************************************************************************/
function page_orderconfirmation() { 
	
	
}

/************************************************************************ 
CHANGE LOGIN CONFIRMATION
************************************************************************/
function page_changeloginconfirmation() {
	

}


/************************************************************************ 
HTML CLEAN UP FOR SIGMACOMMERCE
Sets standard classes on UL, Product Grids, Inputs, etc.
************************************************************************/

// Inputs 
$(document).ready(function() { 
$("input").each(function() {
		$(this).addClass('input-type-'+$(this).attr('type'));
		$(this).parent().addClass('input-container-'+$(this).attr('id').toLowerCase());
		$(this).addClass('input');
		$(this).focus(function() { 
			$(this).addClass("focused"); 
			$(this).parent().addClass("active");
		});
		$(this).blur(function() { 
			$(this).addClass("blurred");
			$(this).removeClass("focused");
			$(this).parent().removeClass("active");
		});
	});
	$('select').each(function() {
		$(this).addClass('input-type-select');
		$(this).parent().addClass('input-container-'+$(this).attr('id').toLowerCase());
	});
	// Tables
	
	$('td.shoppingcartprice').parent().addClass('product-row');
	
	$('table tr').each(function(i) { 
		$(this).addClass("row");
		$(this).addClass("row-"+i);
		if(i%2) {
			$(this).addClass("even-row");
		} else {
			$(this).addClass("odd-row");
		}
		
		$('td:first',this).addClass("first");
		$('td:last',this).addClass("last");
		
	});
	
	$('table tr:first').addClass("first");
	
	$('table tr td').each(function() { 
		if($(this).html().length==0) { 
			
			$(this).html("&nbsp;");
			$(this).addClass("empty-cell");
			// Check if its a TR with no content, if so, lets remove it 
			
		}
	});
	
	// List Items
	$("ul").each(function(){
      $('li:first',this).addClass("first");
			$('li:last',this).addClass("last");
	});
	
	// Sigma Specific Links 
	$('a.currentlink').addClass('link');
	$('a.qlinkstyle').addClass('link');
	$('a.link').hover(function() { $(this).addClass('hover'); }, function() { $(this).removeClass('hover'); });

	//Product Grid
	$('.Products .product').each(function(i) {
		$(this).addClass('product-'+i);
		$('h3 a',this).addClass('product_name_link');
		$('img.product_image',this).parent().addClass('real-product-image-link');

	});
	
	$('.Products').each(function() { 
		if($('.product',this).length==0) {
			$(this).before('<div class="empty-results no-products"></div>');
			$(this).hide();
		}
	});
});

