function validateContactForm(){

	// Validation for contact form
	if($("#contactform").length == 0){
		
		var whereToLook = ".box-contact"
	
	}else{
		var whereToLook = "#content"
		
	}
			
	if(whereToLook == ".box-contact"){
		$(whereToLook + " input:checkbox").attr("checked", false);
		$(whereToLook + " input:first").attr("checked", true);
		$(whereToLook + " li.brochure").hide();
		$(whereToLook + " li.download").hide();
		$(whereToLook + " li.assessment").hide();
		$(whereToLook + " li.callback").show();
	}else{
		var selections = new Array();
		var selectionNumber = 0;
		$(whereToLook + " ul.actions input:checkbox").each(function(i){
			if($(this).attr("checked")){
				selections[selectionNumber] = $(this).attr("id")
				selectionNumber++;
			}
			
		});
		checkedInputs = getCheckedCheckBoxes(whereToLook);
		
		addAndRemoveInputClasses(checkedInputs, selections , whereToLook)
	}
	

	
	$(whereToLook + " ul.actions input:checkbox").unbind().bind('click',function() {
		$(whereToLook + " .missing").remove();
		// Four types of selection that have specific required fields
		
		var selections = new Array();
		var selectionNumber = 0;
		$(whereToLook + " input:checkbox").each(function(i){
			if($(this).attr("checked")){
				selections[selectionNumber] = $(this).attr("id")
				selectionNumber++;
			}
			
		});
				
		
		switch ($(this).attr("id")) {
		
			case 'assessment':
			
				var checkedInputs = 0;
				
				checkedInputs = getCheckedCheckBoxes(whereToLook);
				addAndRemoveInputClasses(checkedInputs, selections, whereToLook);
			break;
			
			case 'brochure': 

				var checkedInputs = 0;
				
				checkedInputs = getCheckedCheckBoxes(whereToLook);				
				addAndRemoveInputClasses(checkedInputs, selections, whereToLook);

			break;
			
			case 'download': 
			
				var checkedInputs = 0;
				
				checkedInputs = getCheckedCheckBoxes(whereToLook);				
				addAndRemoveInputClasses(checkedInputs, selections, whereToLook);

			break;
			
			case 'callback': 

				var checkedInputs = 0;
				
				checkedInputs = getCheckedCheckBoxes(whereToLook);	

				addAndRemoveInputClasses(checkedInputs, selections, whereToLook);

			case 'refer':
				
				checkedInputs = getCheckedCheckBoxes(whereToLook);
				addAndRemoveInputClasses(checkedInputs, selections, whereToLook);
				
			break;
			
			default:
			alert("Sorry we're having difficuties processing your request. Please try again later.")
		}
		
	});
	
	if($(whereToLook + " #infohearabout option:selected").attr("value") == "other"){
		$("#infoother").fadeIn();
	}else{
		$("#infoother").hide();
	}
	
	$(whereToLook + " #infohearabout").unbind().bind('change',function() {
		if($(this).val() == "other"){
			$("#infoother").fadeIn()
		}else{
			$("#infoother").fadeOut()
		}
	
	});
}


function addAndRemoveInputClasses(checkedInputs, selections , whereToLook){

	if(checkedInputs == 0){
		$(whereToLook + " p.req").hide();
		$("#infohearabout").parent().hide()
	}else{
		$(whereToLook + " p.req").show()
		$("#infohearabout").parent().show()
	}
	
	if(whereToLook == "#content"){
		// Full contact form	
		//$(whereToLook + " li.brochure img").remove();
		//$(whereToLook + " li.download img").remove();
		//$(whereToLook + " li.assessment img").remove();
		//$(whereToLook + " li.callback img").remove();
		
		$(whereToLook + " li.brochure img").hide();
		$(whereToLook + " li.download img").hide();
		$(whereToLook + " li.assessment img").hide();
		$(whereToLook + " li.callback img").hide();
		$(whereToLook + " li.refer img").hide();

		checkrefer();
		
		for (x in selections){
			
							
				$(whereToLook + " li." + selections[x] + ">span").each(function(intindex){
					
					$("img", this).show();
							
				});
				$(whereToLook + " li." + selections[x] + ">label").each(function(intindex){
					
					
					$("img", this).show();
							
				});
		}
	}else{
		
		$(whereToLook + " li.brochure").hide();
		$(whereToLook + " li.download").hide();
		$(whereToLook + " li.assessment").hide();
		$(whereToLook + " li.callback").hide();
		$(whereToLook + " li.refer img").hide();
		
		for (x in selections){
			$(whereToLook + " li." + selections[x]).fadeIn()
		}
	}

}

function getCheckedCheckBoxes(whereToLook){
	var getChecked = 0;
	$(whereToLook + " .actions input:checkbox").each(function(i){
		if($(this).attr("checked")){
			getChecked++;
		}
	});
	return getChecked;
}

function checkrefer(){
	if($("#refer").attr("checked")){
		$("li.friend").show();
	}else{
		$("li.friend").hide();
	}
}

function imageContentShadow(){
	if($(".home").length != 1)
	{
		$("#content img").each(function(intindex){
			
			var imgClass = "";
			if($(this).hasClass('wccms_fr')){
				imgClass = " wccms_fr'"
			}else if($(this).hasClass('wccms_fl')){
				imgClass = " wccms_fl'"
			}
			if(this.width > 60){
				$(this).wrap("<span class='imgSpanSpacing"+imgClass+"'><span class='rc-img-tl' style='width:" + (this.width + 18) +"px'><span class='rc-img-tr'><span class='rc-img-br'><span class='rc-img-bl'><span class='divimg'></span></span></span></span></span></span>");
			}
		});	
	}
}



function imageServicesShadow(){
	
	$("div.list-services img").each(function(intindex){
		
		
		var imgClass = "";
	
		var imgClass = "";
		if($(this).hasClass('wccms_fr')){
			imgClass = " wccms_fr'"
		}else if($(this).hasClass('wccms_fl')){
			imgClass = " wccms_fl'"
		}
		
		if($(this).parents("li.fth").length != 1){
			$(this).wrap("<span class='imgSpanSpacing"+imgClass+"'><span class='rc-img-tl' style='width:" + (this.width + 18) +"px'><span class='rc-img-tr'><span class='rc-img-br'><span class='rc-img-bl'><span class='divimg'></span></span></span></span></span></span>");
		}
	});
}

function imageProductsShadow(){
	

	$("div.list-products img").each(function(intindex){
	
		
		if(!$(this).hasClass("wccms_noborder")){
	
			var imgClass = "";

			var imgClass = "";
			if($(this).hasClass('wccms_fr')){
				imgClass = " wccms_fr'"
			}else if($(this).hasClass('wccms_fl')){
				imgClass = " wccms_fl'"
			}
			
			$(this).wrap("<span class='imgSpanSpacing"+imgClass+"'><span class='rc-img-tl' style='width:" + (this.width + 18) +"px'><span class='rc-img-tr'><span class='rc-img-br'><span class='rc-img-bl'><span class='divimg'></span></span></span></span></span></span>");
		}
	});
}

function cmsButtonDecoration(){
	$(".wccms_blue_button a").wrapInner('<span class="btn-bl"><span class="btn-br"><span class="btn-tl"><span class="btn-tr"><span></span></span></span></span></span>');
	$(".wccms_blue_button a").addClass("btn-link");
}


function datePicker(){
	Date.format = 'mm/dd/yyyy';
	$('.date-pick').datePicker().val(new Date().addDays(2).asString()).trigger('change');
}

function lightBoxAddHTML(){
	if($("#gallery").length == 1){
		$('#gallery a').lightBox();
		if($("body.product").length > 0){
			$('#gallerybanner').append('<p class="enlargeimage"><a href="#">Enlarge image</a></p>');
			//$('#gallery').append('<p id="moreimages"><a href="#">More images</a></p>');
		}
	}
}

function loadFlowplayer(linkdest){
    flowplayer(
        "videoplayer",
        "/js/flowplayer-3.1.3.swf",
        linkdest
    );
}

function handleFLVLinks(){

	if($("a[href$='.flv']").length > 0){
		$("#videoplayer").wrap("<div id='videoplayerborder'></div>")
		var linkdest = $("a[href$='.flv']:first").attr("href");
		//loadFlowplayer(linkdest);
	}
	
	$("a[href$='.flv']").unbind().bind('click',function() {
		var linkdest = $(this).attr("href");
		//loadFlowplayer(linkdest);
		
		window.location = "http://" + window.location.host + window.location.pathname + "?video=" + linkdest;
		return false;
	});
	

}

function youtubeVideos(){
	
	if($("#YoutubeEmbeddedPlayer").length > 0){
		$("#YoutubeEmbeddedPlayer").wrap("<div id='videoplayerborder'></div>")
		$("#youtubevideos a").unbind().bind('click',function() {
			
			var autoPlay = "&autoplay=1";
			
			joinTogether = $(this).attr("href") + autoPlay;
			
			var strHTML = '<object height="296" width="423"><param value="' + joinTogether +'" name="movie" id="parammoviename"/><param value="true" name="allowFullScreen"/><param value="always" name="allowscriptaccess"/><embed height="296" width="423" allowfullscreen="true" allowscriptaccess="always" type="application/x-shockwave-flash" src="' + joinTogether +'" id="embedmoviename"/></object>';
			
			//alert(strHTML)
			
			$("#YoutubeEmbeddedPlayer").empty()
			
			$("#YoutubeEmbeddedPlayer").append(strHTML);

			//$("#YoutubeEmbeddedPlayer #parammoviename").attr("value" , joinTogether);			
			//$("#YoutubeEmbeddedPlayer #embedmoviename").attr("src" , joinTogether);
			
			return false;
		});
	}
}


function linkIncreaseAds(){
	
	$(".list-services li,.list-products li").bind('click', function(){
		var checkedForMatch = checkformatch(this)
		
			if(checkedForMatch){
				var linkIs = $("a", this)[0].href;
				window.location = linkIs;
			}
	});
	
	
	$(".list-services li,.list-products li").bind('mouseover', function(){
		var checkedForMatch = checkformatch(this)
			
		if(checkedForMatch){
			$(this).css({cursor:"pointer"});
			$("a", this).css({textDecoration:"none"});
		}
	}).bind("mouseout",function(){
		var checkedForMatch = checkformatch(this)
		
		if(checkedForMatch){
			$("a", this).css({textDecoration:"underline"});
		}
	});
}

function checkformatch(listItem){
	if ($("a",listItem).length > 0){
		
			var link = "";
			var prevLink = "";
			var linksdontmatch = false;
			
			$("a",listItem).each(function(intindex){
				link = $(this).attr("href");
				if(intindex !=0){
					if (link != prevLink){
						
					}else{
						linksdontmatch = true
					}
				}
				prevLink = link
			});
			
		}
		
		if (linksdontmatch == true){
			return true;
		}else{
			return false;
		}
}

function loadIE7Functions(){
	lightBoxAddHTML();
	handleFLVLinks();
	youtubeVideos();
	linkIncreaseAds();
	datePicker();
	//imageServicesShadow();
	//imageProductsShadow();
}

$(document).ready(function () {
	if ($.browser.msie){
		if(parseInt($.browser.version) <= 6){
		}
		else{
			loadIE7Functions()
		}
		
	}else{
		loadIE7Functions();
	}
	// IE6 functions listed here

		validateContactForm();

	cmsButtonDecoration();

});

$(window).ready(function () {
 	//videoShadow();
	//imageContentShadow();
});





