﻿// JScript File

    //Shadowbox.init();

	var $j = jQuery.noConflict();
	
	function resize()
	{
	
		var hite = $j(document).height();
		// let's say min height 
		//hite = $j(document).height();
		
		if(hite<830)
		{
			$j("#Flowers").height(830);
		} else {
			$j("#Flowers").height(hite);
		}
	}
	
	$j(window).resize(function() {
	  	
		resize();
	  
	});
	function ResizeEventImages()
	{
		$j('#EventsResizingTable img').each(function() {
			var maxWidth = 200; // Max width for the image
			var maxHeight = 500;    // Max height for the image
			var ratio = 0;  // Used for aspect ratio
			var width = $j(this).width();    // Current image width
			var height = $j(this).height();  // Current image height
		
			// Check if the current width is larger than the max
			if(width > maxWidth){
				ratio = maxWidth / width;   // get ratio for scaling image
				$j(this).css("width", maxWidth); // Set new width
				$j(this).css("height", height * ratio);  // Scale height based on ratio
				height = height * ratio;    // Reset height to match scaled image
			}
		
			// Check if current height is larger than max
			if(height > maxHeight){
				ratio = maxHeight / height; // get ratio for scaling image
				$j(this).css("height", maxHeight);   // Set new height
				$j(this).css("width", width * ratio);    // Scale width based on ratio
				width = width * ratio;    // Reset width to match scaled image
			}
		});
	}
	$j(document).ready(function() {

		//Shadowbox.loadPlayer(['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'], 'shadowbox/player'); 
		Shadowbox.init({
			handleOversize:     "drag",
			displayNav:         false,
			handleUnsupported:  "remove",
			autoplayMovies:     true,
			players:  ['flv', 'html', 'iframe', 'img', 'qt', 'swf', 'wmp'],
			troubleElements: ['select', 'object', 'embed']
		});

		var divHite = $j('#BodyConentWrap').height();
		
		var white = $j(window).height();
		
		if(divHite < 515){
			$j('#BodyConentWrap').height(515);
		}
		if($j('#BodyConentWrap').height() < $j('#contentFooter').height())
		{
			$j('#BodyConentWrap').height($j('#contentFooter').height());
		}
		
		resize();
		ResizeEventImages();
		
		//Cufon.replace('#topNav a');
		Cufon.replace('#topNav .sel', { fontFamily: 'NeutraText' });
		Cufon.replace('#topNav .norm', { fontFamily: 'NeutraText' });
		Cufon.replace('#HomeContent strong', { fontFamily: 'NeutraText' });
		Cufon.replace('#CCNewsletter .heading', { fontFamily: 'NeutraText' });
		Cufon.replace('#CCNewsletterPadding .heading', { fontFamily: 'NeutraText' });
		Cufon.replace('h1', { fontFamily: 'NeutraText' });
		Cufon.replace('h2', { fontFamily: 'NeutraText' });
		Cufon.replace('h3', { fontFamily: 'NeutraText' });
		Cufon.replace('h4', { fontFamily: 'NeutraText' });
		Cufon.replace('h5', { fontFamily: 'NeutraText' });
		Cufon.replace('h6', { fontFamily: 'NeutraText' });
		Cufon.replace('#sidebar ul li', { fontFamily: 'NeutraText' });
		Cufon.replace('.promoAmount', { fontFamily: 'HelveticaNeue' });
		Cufon.replace('#greentip_large_bg_sun .title', { fontFamily: 'Marydale'});
		Cufon.replace('.promobox .marydale', { fontFamily: 'Marydale'});
		//Cufon.replace('#ContactPostcontent h1');
		
		//EventsResizingTable
		
		$j("#topNav .norm").hover(
		  function () {
			$j(this).css("color","#00703c");
			Cufon.replace('#topNav .norm');
		  }, 
		  function () {
		  	
			$j(this).css("color","#591f00");
			Cufon.replace('#topNav .norm');
		  }
		);

		$j("#sidebar ul li .norm a").hover(
		  function () {
			$j(this).css("color","#00703c");
			Cufon.replace('#sidebar ul li .norm a');
		  }, 
		  function () {
		  	
			$j(this).css("color","#591f00");
			Cufon.replace('#sidebar ul li .norm a');
		  }
		);
		
		$j("#zipcode").focus(function ()
		{ 
			if(this.value = "zip code")
				this.value = "";
			$j(this).css("color","#333333");
		});
		$j("#zipcode").blur(function ()
		{ 
			if(this.value == "" || this.value == " ")
			{
				this.value = "zip code";
				$j(this).css("color","#9A8479");	
				}
			
		});
		
		$j("[name=your-email]").focus(function ()
		{ 
			if(this.value = "Email Address")
				this.value = "";
			$j(this).css("color","#333333");
		});
		$j("[name=your-email]").blur(function ()
		{ 
			if(this.value == "" || this.value == " ")
			{
				this.value = "Email Address";
				$j(this).css("color","#9A8479");
				}
				
		});
		
		$j("#mlzip").focus(function ()
		{ 
			if(this.value == "Zip Code")
				this.value = "";
			$j(this).css("color","#333333");
			//$j(this).setSelectionRange(1, 1);
			//setSelectionRange($j(this), 0, 0);
		});
		$j("#mlzip").blur(function ()
		{ 
			if(this.value == "" || this.value == " ")
			{
				this.value = "Zip Code";
				$j(this).css("color","#9A8479");
				}
				
		});
		var ctype = "";
		ctype = getQuerystring('type')
		if(ctype == "testimonial")
		{
			$j("[name=reason]").val("Testimonial");

		}
		$j("[name=reason]").change(function() {
			if(this.value == "Where to buy")
			{	
				window.location = "/store-finder"
				//$j("#storefinderpop").show();
				//alert($j("#storefinderpop").show());
			}
			else
			{
				$j("#storefinderpop").hide();
				//alert("hide");
			}
		});
		
		/*$j("#recyleclick").click(function(){ 
			//alert("clicky");
			$j("#recyleclick").colorbox({rel:'flipbook'});				
			//$j("a[rel='flipbook']").colorbox({slideshow:true});		
			return false;
		});*/
			
		$j("a[rel='flipbook']").colorbox();	//{ width:620, height:421}
		$j("a[rel='videogallery']").colorbox({iframe:true, width:600, height:500});
		$j("#timelinemap area").colorbox();
		$j('.community_slideshow').cycle({ fx: 'fade', speed: 500, timeout: 5000 });
 	});
	

	addEvent(window, 'load', initCorners);
	function initCorners() {
		var settings = {
		  tl: { radius: 8 },
		  tr: { radius: 8 },
		  bl: { radius: 8 },
		  br: { radius: 8 },
		  antiAlias: true,
		  autoPad:true
	    }
		var smallsettings = {
		  tl: { radius: 4 },
		  tr: { radius: 4 },
		  bl: { radius: 4 },
		  br: { radius: 4 },
		  antiAlias: true,
		  autoPad:true
	    }
	
    curvyCorners(settings, "#CCNewsletter");
	curvyCorners(settings, "#CCNewsletter_sm");
	curvyCorners(settings, "#FindAStore");
	curvyCorners(smallsettings,"#OurStoryBox");
	curvyCorners(smallsettings,"#TestimonialBox");
	//curvyCorners(smallsettings,"#promotionsLarge");
	curvyCorners(settings, "#NewTestimonialBox");
  
	curvyCorners(settings, "#refine-search");
	curvyCorners(settings, ".rs-location");
	curvyCorners(settings, ".rs-product-type");
	curvyCorners(settings, ".did-you-know");
	curvyCorners(settings, "#dvErr");
	}
	function getQuerystring(key, default_)
	{
	  if (default_==null) default_="";
	  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
	  var qs = regex.exec(window.location.href);
	  if(qs == null)
		return default_;
	  else
		return qs[1];
	}
  function validateZip()
  {
  	var inpVal = parseInt($j("#zipcode").val(), 10);										
	if($j("#zipcode").val() == "" || isNaN(inpVal) || $j("#zipcode").val().length != 5)
	{
		/*Error = true;
		$("#txtZipCode").removeClass('input').addClass('input_error');
		$("#spnZipCode").css('display','inline');*/
		return false;
	}
	else
		return true;
	
  }
  function isValidEmail(str) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
												return reg.test(str);
	}
  function SuccessContact()
  {
  		var name = $j("[name=Name]").val();	
		var p1 = $j("[name=phonearea]").val();	
		var p2 = $j("[name=phone1]").val();	
		var p3 = $j("[name=phone]").val();	
		var email = $j("[name=contactemail]").val();
		var address = $j("[name=Address]").val();	
		var city = $j("[name=City]").val();
		var state = $j("[name=state]").val();
		var zip = $j("[name=contactzip]").val();
		var reason = $j("[name=reason]").val();
		if(name != "" && p1 != "" && p2 != "" && p3 != "" && email != "" && address != "" && city != "" && state != "select" && zip != "" && reason != "Select One")
		{
			 Shadowbox.open({
				content : '/contact-thankyou.html'
						 , player : 'iframe'
						 , title : '',
				height:     310,
				width:      690
			});
		}
  }
  function validateyourzip()
  {
  	
	if ($j("#CCNewsletter").length ) 
	{
		//home page newsletter
		var inpVal = parseInt($j("[name=your-zip]").val(), 10);	
		var email = $j("[name=your-email]").val();		
		if((email == "Email Address" || !isValidEmail(email)) && ($j("[name=your-zip]").val() == "" || isNaN(inpVal) || $j("[name=your-zip]").val().length != 5))
		{
			$j(".emailinput").append("<span class='mmf-not-valid-tip'> </span>");//Please enter a valid email.
			$j(".emailinput").mouseover(function() {
				$j(".emailinput.mmf-not-valid-tip").fadeOut('fast');
				$j(".emailinput .mmf-not-valid-tip").remove();
			});
			
			
			$j(".zipinput").append("<span class='mmf-not-valid-tip' ></span>");//Please enter a valid zip code.
			$j(".zipinput").mouseover(function() {
				$j(".zipinput.mmf-not-valid-tip").fadeOut('fast');
				$j(".zipinput .mmf-not-valid-tip").remove();
			});
			return false;
		}
		else if(email == "Email Address" || !isValidEmail(email))
		{
			$j(".emailinput").append("<span class='mmf-not-valid-tip' ></span>");//Please enter a valid email.
			
			$j(".emailinput").mouseover(function() {
				$j(".mmf-not-valid-tip").fadeOut('fast');
				$j(".emailinput .mmf-not-valid-tip").remove();
			});
			return false;
		}						
		else if($j("[name=your-zip]").val() == "" || isNaN(inpVal) || $j("[name=your-zip]").val().length != 5)
		{
			//alert("hit");
			$j(".zipinput").append("<span class='mmf-not-valid-tip' ></span>");//Please enter a valid zip code.
			
			$j(".zipinput").mouseover(function() {
				$j(".mmf-not-valid-tip").fadeOut('fast');
				$j(".zipinput .mmf-not-valid-tip").remove();
			});
			return false;
		}
		else
		{
			$j(".mmf-not-valid-tip").css("display","none");
			
			 Shadowbox.open({
			 	content : '/nl-thankyou.html'
                         , player : 'iframe'
                         , title : '',
				/*content:    '<div id="welcome-msg">Welcome to my website!</div>',
				player:     "html",
				title:      "Welcome",*/
				height:     310,
				width:      690
			});



			return true;
		}
	}
	else
	{
	 	//side bar newsletter
		var inpVal = parseInt($j("[name=your-zip]").val(), 10);	
		var email = $j("[name=your-email]").val();		
		if((email == "Email Address" || !isValidEmail(email)) && ($j("[name=your-zip]").val() == "" || isNaN(inpVal) || $j("[name=your-zip]").val().length != 5))
		{
			$j(".emailinput").append("<span class='mmf-not-valid-tip' ></span>");//Please enter a valid email	
			$j(".emailinput").mouseover(function() {
				$j(".mmf-not-valid-tip").fadeOut('fast');
				$j(".emailinput .mmf-not-valid-tip").remove();
			});
			
			$j(".zipinput").append("<span class='mmf-not-valid-tip' ></span>");//Enter a valid zip.
			$j(".zipinput").mouseover(function() {
				$j(".mmf-not-valid-tip").fadeOut('fast');
				$j(".zipinput .mmf-not-valid-tip").remove();
			});
			return false;
		}
		else if(email == "Email Address" || !isValidEmail(email))
		{
			$j(".emailinput").append("<span class='mmf-not-valid-tip' ></span>");	//Please enter a valid email.
			$j(".emailinput").mouseover(function() {
				$j(".mmf-not-valid-tip").fadeOut('fast');
				$j(".emailinput .mmf-not-valid-tip").remove();
			});
			return false;
		}						
		else if($j("[name=your-zip]").val() == "" || isNaN(inpVal) || $j("[name=your-zip]").val().length != 5)
		{
			$j(".zipinput").append("<span class='mmf-not-valid-tip' ></span>");	//Enter a valid zip.
			$j(".zipinput").mouseover(function() {
				$j(".mmf-not-valid-tip").fadeOut('fast');
				$j(".zipinput .mmf-not-valid-tip").remove();
			});
			return false;
		}
		else
		{
			Shadowbox.open({
			 	content : '/nl-thankyou.html'
                         , player : 'iframe'
                         , title : '',
				/*content:    '<div id="welcome-msg">Welcome to my website!</div>',
				player:     "html",
				title:      "Welcome",*/
				height:     310,
				width:      690
			});
			$j(".mmf-not-valid-tip").css("display","none");
			return true;
		}
	}
  }
