$(document).ready(function() {
//**** SITE SPECIFIC ****//
//-----------------------//

//------> end site specific

//**** TESTING NEW FEATURES ****//
//-----------------------------//

/*
//Local delivery link
$('#ctl00_ContentPlaceHolder1_btnShipCost').click(function(){
setTimeout(function(){
$('.tblShippingCostsMeth').each(function(){
if ($(this).text().match(/FREE! Local Delivery/)){$(this).html("<a href='#' style='font-weight:bold;font-size:15px;text-decoration:underline;'>FREE! Local Delivery</a>");}
});
}, 3000)
});
*/

//------> end testing new features

//superfish dropdown menu
if($('.sf-menu').length){$("ul.sf-menu").superfish();}

//call newsletter sign up put div "news-signup" on page 
//ccNewsletter('1102000675072', 'Enter Email', '#999', '#000');

//default text for search box
searchBoxText('Search...');

//iplocation using google api
//googleIpLoacator();

//change cart pic when it has items
if($('#cartpic').length){cartPicChange();}

//navigation active page determination
navActive();

//make portal form submit when enter is pressed -site number argument
portalFormSubmit('219');

//conformation alert for edoc builder
if ($('body').hasClass('productCustomize')){
	edocConfirmationNotice();
}

//******* ProductDetail Page functions ********//
if ($('body').hasClass('productDetail')){

	//call for information entered into calculator
	if($('#detailPage_calculator').length){$(calcjunk(0,true,false,false));}
	
	//edit estimate shipping input, remove "postal code" and add auto fill: arg = text inside input box
	betterShipEstimateInput("Enter Zip Code");
	
	//print estimated ship date to calculator based on customer choice of 1 Day, 2 Day, etc...
	if ($('.calc-detail-wrap').length){getShipDate();}
	
	//toottips on product detail page, pre ajax
	calcTooltips();
	
	//add link next to add to cart button, arg = storepage id
	addToCartAgreement('1213');
	
	//additon of all product navigation in the product detail header
	//productDetailMenu();
	
	//product detail, notice for no file uploaded
	calcFileUploadNotice();
	
	//Remove line breaks in file upload fields and other places
	detailPageBrCleanup();

}// .eof product detail page functions


//******* StoreForm Page functions ********//
if ($('body').hasClass('storeForm')){

	//Remove line breaks in file upload fields and other places
	formBrCleanup();
	
	//captcha check //needs getUrlParam plugin
	formCaptchaCheck();

}// .eof store form page functions

//home page splash transition
if ($('#s2').length){
$('#s2').cycle({ 
    fx:     'fade', 
    speed:  500,
	pause: 1,
    timeout: 9000
});
}
//----->>

//home page slider transition
if ($('#slider').length){
		function formatText(index, panel) {return index + "";}
        $(function () {
            $('#slider').anythingSlider({
                easing: "linear",        // Anything other than "linear" or "swing" requires the easing plugin
                autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
                delay: 5000,                    // How long between slide transitions in AutoPlay mode
                startStopped: false,            // If autoPlay is on, this can force it to start stopped
                animationTime: 250,             // How long the slide transition takes
                hashTags: true,                 // Should links change the hashtag in the URL?
                buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
        		pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
        		startText: "Go",             // Start text
		        stopText: "Stop",               // Stop text
		        navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
            });
            
            $("#slide-jump").click(function(){$('#slider').anythingSlider(1);});   
        });
}
//---->>

//Begin shopcart images///////////
var price = 0;
$('.shopCartCellPrice').each(
	function(i){ price += parseInt($(this).html().replace(/[$,]/g, "")); });
if (price >= 100){$('#shopcart-offer').show();}
$('.shopCartCellItem').each(
		function(i){
			switch($(this).html()){
				//name of product how it appears in cart, number of image in products dir on server
				case 'Color Copies - Try it!': img = "15301";
					break;
				case '3.5" x 4.25" Memo Pads': img = "15364";
					break;
				default: img ="11108";
			}
			$(this).append('<img class="listPage_categoryImage" style="margin:0 auto;" src="/sites/952/images/products/' + img + '_thumb.jpg"/>');
		});
//end shopcart images///////////

if ($("#ctl00_ContentPlaceHolder1_lnkNewAccount").length){$("#ctl00_ContentPlaceHolder1_lnkNewAccount").text("Create an Account");}//text change on login page
if ($('body').hasClass('checkout')){$("#ctl00_ContentPlaceHolder1_lblInformation").hide();}

});//eof .ready()/////////////////////////////////////////////////////////////////////////////////////

//navigation active page determination //needs getUrlParam plugin
function navActive(){
	var storePageParam = $(document).getUrlParam("id");
	var productPageParam = $(document).getUrlParam("p");
	var catPageParam = $(document).getUrlParam("c");
	$('.navlinks a').each(function(){
		var navLinkHref = $(this).attr('href').match(/\d+/);
		if (navLinkHref == null){}
		else if (navLinkHref == storePageParam || navLinkHref == productPageParam || navLinkHref == catPageParam){
			$(this).addClass('navActive');
		}
	})
}
//------>

//switch cart image from empty to full when cart has products
function cartPicChange(){
var cartValue = $("#abreviatedCart").text().match(/\d+/);
if (cartValue > 0){$("#cartpic").removeClass().addClass("cartpic2");}
}
//----->>

//google ip locator
function googleIpLoacator(){
if(google.loader.ClientLocation){ visitor_lat = google.loader.ClientLocation.latitude;visitor_lon = google.loader.ClientLocation.longitude;visitor_city = google.loader.ClientLocation.address.city;visitor_region = google.loader.ClientLocation.address.region;visitor_country = google.loader.ClientLocation.address.country;visitor_countrycode = google.loader.ClientLocation.address.country_code;
	$("#main").append("<div id='ipinfo'><ul><li><strong>Customer Info:</strong></li><li>Latitude: " + visitor_lat + " <\/li><li>Longitude: " + visitor_lon + " <\/li><li>City: " + visitor_city + " <\/li><li>Region: " + visitor_region + " <\/li><li>Country: " + visitor_country + " <\/li><li>Country Code: " + visitor_countrycode + " <\/li><\/ul><\/div>");
}
else{$("#main").append("<div id='ipinfo' class='sideNav'><div style='padding:10px;'>No ip info found.<\/div><\/div>");
}
}
//.eof formProcessNotice---->>

//newsletter signup ,Enter Your Email, #999, #000 //needs autofill function also
function ccNewsletter(siteNumber, ccTextValue, ccTextColor, ccActiveTextColor){
if ($('#news-signup').length){
$('#news-signup').html('<fieldset><ul><li><input id="news-text" type="text" name="userName" /><input id="news-submit" type="submit" name="submit" value="Go" /><input id="news-id" type="hidden" name="userName" value="' + siteNumber + '" /></li><li><div> <a href="http://www.constantcontact.com/safesubscribe.jsp" target="_blank"> <img src="http://img.constantcontact.com/ui/images1/safe_subscribe_logo.gif" border="0" width="168" height="14" alt=""/></a> </div></li></ul></fieldset>');
//newsletter text change in input box - uses autofill function
$('#news-text').autofill({value: ccTextValue,defaultTextColor: ccTextColor,activeTextColor: ccActiveTextColor});
if ($('#news-text').length){$(function() {$("#news-text").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
window.open("http://visitor.constantcontact.com/d.jsp?m=" + $('#news-id').val() + "&p=oi&ea=" + $('#news-text').val())
return false;} else {return true;}});});};
//Submit newsletter sign up 
$("#news-submit").click(function(e) {e.preventDefault();window.open("http://visitor.constantcontact.com/d.jsp?m=" + $('#news-id').val() + "&p=oi&ea=" + $('#news-text').val())});
};}
//--->

//search box default text
function searchBoxText(defaultText){				   
var clearMePrevious = defaultText; $('#ctl00_searchBox').val(defaultText);
// clear input on focus
$('#ctl00_searchBox').focus(function(){if($(this).val()== defaultText){clearMePrevious = $(this).val();$(this).val("");}});
// if field is empty afterward, add text again
$('#ctl00_searchBox').blur(function(){if($(this).val()==""){$(this).val(clearMePrevious);}});
}
//---->>

//make portal form submit when enter is pressed
function portalFormSubmit(siteNumber){
if ($('#port-login input').length){$(function() {$("#port-login input").keypress(function (e) {
if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13)) {
window.location="http://www.printerorder.com/login.aspx?pid=" + siteNumber + "&userEmail=" + $('#portUserName').val() + "&userPassword=" + $('#portPassword').val()
return false;} else {return true;}});});};
//Submit portal information to url and redirect page 
if ($('#port-login-submit').length){$("#port-login-submit").click(function(e) {   e.preventDefault();
window.location="http://www.printerorder.com/login.aspx?pid=" + siteNumber + "&userEmail=" + $('#portUserName').val() + "&userPassword=" + $('#portPassword').val()}); };
}