$(document).ready(function(){
	
	/*
	----------------------------------------------------------
	GENERAL
	---------------------------------------------------------- */
	if ($.client.os == 'Windows') {  $("body").addClass("win");  }

	// EXTERNAL WINDOWS
	$('a[rel="external"]').click( function() {
        window.open( $(this).attr('href') );
        return false;
    });


	// MONCUR LOGO ANIM
	$("#moncur a em").hide();
	$("#moncur a").hover(function() {
		$(this).find("em").animate({opacity: "show"}, "slow");
	}, function() {
		$(this).find("em").animate({opacity: "hide"}, "fast");
	});


	// MAKE ENTIRE BLOCK CLICKABLE
	$(".highlight").click(function(){
		if($(this).find("a").attr("rel") == "external") {
		    window.open($(this).find("a").attr("href"))
		} else{
		    window.location=$(this).find("a").attr("href"); return false;
		    return;
		}
	});
	
	
	// WRAP
	$("#primary li a.main").wrapInner("<span></span>");
	$("#utility li a").wrapInner("<span></span>");
	
	// ADD CLASS
	$("#subsections ul li:nth-child(even)").addClass("nomargin");
	$("div.locations div:nth-child(even)").addClass("nomargin");
	$("div.industries div:nth-child(even)").addClass("nomargin");
	$("ul.audiences li:nth-child(even)").addClass("nomargin");
	
	// APPEND
	$("#content-main div.contact").append("<span class='icons'></span>");
	$("div.audiences").append("<span class='icons'></span>");
	$("div.industries div").append("<span class='icons'></span>");
	$("div.locations div").append("<span class='icons'></span>");
	$("ul.append li").append("<span class='icons'></span>");
	$("ul.callout").append("<span class='icons'></span>");
	$("#cust-exp.answers").append("<span class='icons'></span>");
	$("#email-validation").append("<span class='icons'></span>");



	/*
	----------------------------------------------------------
	CAROUSELS
	---------------------------------------------------------- */
	$('#panels').orbit({
		animation: 'fade',
		timer: true,
		advanceSpeed: 5000,
		directionalNav: true,
		captions: false,
		bullets: true,
		randomize:true
	});
	
	// PHOTO GALLERY
	$('#photo-gallery').orbit({
	     animation: 'fade',
	     timer: false,
	     directionalNav: true,
	     captions: true
	});
	
	$("#home ul.orbit-bullets").wrap("<div id='bullets' class='wrap'></div>");
	$("#home div.slider-nav").wrap("<div id='directional' class='wrap'></div>");



	/*
	----------------------------------------------------------
	TABS
	---------------------------------------------------------- */
	$("article.tabs section div").hide();
	$("article.tabs section:first div").show();
	$("article.tabs section:first").addClass("active");
	$("article.tabs").css("height", $("article.tabs section:first div").height() + 70);

	$("article.tabs section h1").click(function(){
		$("article.tabs section").removeClass("active");
		$(this).parent("section").addClass("active");
		$("article.tabs section:not('.active') div").hide();
		$("section.active div").fadeIn("fast");
		$("article.tabs").css("height", $("section.active div").height() + 70);				
		$.cookie( $(this).parents("article").attr('id'), $(this).html());
		return false;
	});
	
	// SET DEFAULT TAB
	$("article.tabs").each(function(index) {		
		if ( $.cookie($(this).attr('id')) ) {		
			$(this).children('section').each(function(index) {			
				if ( $(this).children("h1").html() == $.cookie(  $(this).parent("article").attr('id') ) )  { $(this).children("h1").trigger('click'); };		
			});
		};	
	});
	
	
	
	/*
	----------------------------------------------------------
	CLIENTS
	---------------------------------------------------------- */
	$("#about ul.clients li a").wrapInner("<span></span>");
	$("#about ul.clients li").hover(function() { 
			var thumbOver = $(this).find("img").attr("src"); 
			$(this).find("a").css({'background' : 'url(' + thumbOver + ') no-repeat left bottom'}); // fade grayscale img out 
			$(this).find("span").stop().fadeTo('fast', 0 , function() {
				$(this).hide() //Hide the image after fade
			}); 
			
		} , function() { 
			$(this).find("span").stop().fadeTo('fast', 1).show(); // fade grayscale img in
	});
	

	/*
	----------------------------------------------------------
	BIOS
	---------------------------------------------------------- */
	$("div.bio p.more a").toggle(function(){
	   $(this).parents().prev(".full").fadeIn("normal").addClass("shown");
	   $(this).text("Show Less");
	   $(this).attr("title", "Show Less");
	},function(){
	   $(this).parents().prev(".full").removeClass("shown").fadeOut("fast");
	   $(this).text("Show More");
	   $(this).attr("title", "Show More");
	});
		
			
		
	/*
    ----------------------------------------------------------
    FORMS
    ---------------------------------------------------------- */
    $.validator.addMethod("phone", function (value, element) {
        return this.optional(element) || /^[0-9\-\+]+$/i.test(value);
    }, "Phone must contain only numbers, + and -.");

    $.validator.addMethod("zipcode", function (value, element) {
        return this.optional(element) || /^[0-9]+$/i.test(value);
    }, "Zip code must contain only numbers.");


	// VALIDATION
    $("#contact-general").validate({
		rules: { industry: "required" },
		messages: { industry: "" }
	});
	
	$("#contact-optout").validate(
		{
			rules: {
				contact_email: {
					required: "#check_email:checked"
				},
				contact_phone: {
					required: "#check_phone:checked"
				},
				contact_fax: {
					required: "#check_fax:checked"
				}
			},
			
			messages: {
			}
		}
	);	
	
	
	// SURVEY SUPPORT
    $("#contact-survey").validate(
		{
			rules: {
				issue: "required"
			},
			messages: {
				issue: ""
			}
		}
	);	
	$("#contact-chinese").validate();
	$("#email-validation").validate();
	
	
	
	// SELECT MENU RENDERING
	$("form select").chosen();
	
		
	// OTHER INDUSTRY REVEAL
	$("#other").hide();
		
	$("#industry_chzn li").click(function(){
		$("#other").animate({ opacity: "hide" }, "normal");
		$("#other").val("");
	});
	
	$("#industry_chzn_o_6").click(function(){
		$("#other").animate({ opacity: "show" }, "normal");
	});
	
		
	// OTHER RESEARCH INTERESTS REVEAL
	$("#contact-general div.toggle").hide();
	$("#research_other").change(function () {
        $("#contact-general div.toggle").animate({ opacity: "toggle" }, "normal");
    });

	$("#industry.valid").find("#industry_chzn").addClass("valid");
	$("#industry.error").find("#industry_chzn").addClass("error");

		
	// DO NOT CONTACT REVEAL	
	$("#contact-optout div.toggle").hide();
	$("#contact-optout label.rounded").change(function () {  
        $(this).next("div.toggle").animate({ opacity: "toggle" }, "normal");
		$(this).toggleClass("selected")
    });
		
		
	// OTHER SURVEY ISSUES REVEAL
	$("#contact-survey div.toggle").hide();
	$("#issues_other").change(function () {
        $("#contact-survey div.toggle").animate({ opacity: "toggle" }, "normal");
	});
		
		
});
// END ON READY

$(document).ready(function(){
  $(window.location.hash).append('<a name="' + window.location.hash.replace('#','')+ '"></a>');
  // window.location.href=window.location.href;
});
