$(document).ready(function(){
	var contentType1Num = $("#contentArea1 .content").size(); var contentType2Num = $("#contentArea2 .content").size(); var contentType3Num = $("#contentArea3 .content").size();
	var currentActive1 = 1; var currentActive2 = 1; var currentActive3 = 1;

	// *** Set Initial Content Open *** //
	$(".content").hide(); $(".content1").show();
	
	$(".arrowSet").hide();

	$(".mainContentArea").hover(function(){$(this).find(".arrowSet").fadeIn(200);}, function(){$(this).find(".arrowSet").fadeOut(300);})
	

	$(".mainContentArea div.content").hover(function(){ 
		if($(this).hasClass("hoverColor1")){ $(this).parent().animate({ backgroundColor: 'color1' }, 300); } 
		else if($(this).hasClass("hoverColor2")){ $(this).parent().animate({ backgroundColor: 'color2' }, 300); }
		else if($(this).hasClass("hoverColor3")){ $(this).parent().animate({ backgroundColor: 'color3' }, 300); }
		else if($(this).hasClass("hoverColor4")){ $(this).parent().animate({ backgroundColor: 'color4' }, 300); }
		else if($(this).hasClass("hoverColor5")){ $(this).parent().animate({ backgroundColor: 'color5' }, 300); }
	}, function(){ 
		$(this).parent().animate({ backgroundColor: 'color100' }, 300);
	})
	
	$(".arrowLink").hover(function(){$(this).addClass("arrowLinkHover");}, function(){$(this).removeClass("arrowLinkHover");})

	$(".showPYV .arrowLink").click(function(){
		if($(".planYourVisitHomeReveal").hasClass("revealed")){
			$(".planYourVisitHomeReveal").slideUp(300);
			$(".planYourVisitHomeReveal").removeClass("revealed");
			$(".arrowLink img").attr("src","http://mobia.org/assets/arrow-right.png");
			$(this).removeClass("arrowLinkActive");
		} else {
			$(".planYourVisitHomeReveal").slideDown(300);
			$(".planYourVisitHomeReveal").addClass("revealed");
			$(".arrowLink img").attr("src","http://mobia.org/assets/arrow-down.png");
			$(this).addClass("arrowLinkActive");
		}
	})
	
	$("#contentArea1 .arrowRightContent").click(function(){ currentActive1 = currentActive1+1; if(currentActive1 > contentType1Num){currentActive1 = 1; } $(this).parent().parent().find(".content").fadeOut(300); $(this).parent().parent().find(".content"+currentActive1).fadeIn(300); })
	$("#contentArea1 .arrowLeftContent").click(function(){ currentActive1 = currentActive1-1; if(currentActive1 == 0){currentActive1 = contentType1Num; } $(this).parent().parent().find(".content").fadeOut(300); $(this).parent().parent().find(".content"+currentActive1).fadeIn(300); })
	
	$("#contentArea2 .arrowRightContent").click(function(){ currentActive2 = currentActive2+1; if(currentActive2 > contentType2Num){currentActive2 = 1; } $(this).parent().parent().parent().find(".content").fadeOut(300); $(this).parent().parent().parent().find(".content"+currentActive2).fadeIn(300); })
	$("#contentArea2 .arrowLeftContent").click(function(){ currentActive2 = currentActive2-1; if(currentActive2 == 0){currentActive2 = contentType2Num; } $(this).parent().parent().parent().find(".content").fadeOut(300); $(this).parent().parent().parent().find(".content"+currentActive2).fadeIn(300); })
	
	$("#contentArea3 .arrowRightContent").click(function(){ currentActive3 = currentActive3+1; if(currentActive3 > contentType3Num){currentActive3 = 1; } $(this).parent().parent().parent().find(".content").fadeOut(300); $(this).parent().parent().parent().find(".content"+currentActive3).fadeIn(300); })
	$("#contentArea3 .arrowLeftContent").click(function(){ currentActive3 = currentActive3-1; if(currentActive3 == 0){currentActive3 = contentType3Num; } $(this).parent().parent().parent().find(".content").fadeOut(300); $(this).parent().parent().parent().find(".content"+currentActive3).fadeIn(300); })
	
	$(".arrowSet li div").hover(function(){$(this).addClass("hover");}, function(){$(this).removeClass("hover");})
	$("#header h4 a").hover(function(){$(this).addClass("active");}, function(){$(this).removeClass("active");})
	
	$("#header h4.removeLink a").each(function(){$(this).removeAttr("href");})
	$("#header h4.removeLink a").click(function(){ 
		if($(this).parent().parent().children("ul").is(":visible")){
			$(this).parent().parent().children("ul").slideUp(200);
			//$(this).parent().parent().children("ul").fadeTo("100",".01");
		} else {
			$(this).parent().parent().children("ul").slideDown(200);
			//$(this).parent().parent().children("ul").fadeTo("100","1");
		}
	})
	
	/*$(".navWrapper").each(function(){
		$(this).children("ul").fadeTo("1",".01",function(){$(this).hide();});
	})*/
	$("#content #layout3Col .col2 p:first").addClass("enlarged");
	


	$(window).scroll(function(){
		if  ($(window).scrollTop() > 225){
			$("#header").css({"position":"fixed", "top":"-225px"});
		} else {
			$("#header").css({"position":"relative", "top":"0"});
		}
	});


	/* #### DS Slideshow specific #### */
	/* #### #### #### #### #### #### #### #### #### #### */

	var iconsName = "slideshowThumbnails"; // Name of the DIV holding the thumbnails
	var numberOfObjects = $(".objSlideshowLI").size();
	var totalWidth = (numberOfObjects*400)+600;
	var currentNumber = 0;
	var currentSlideshowNumber = 1;
	var currentMargin = 0;
	var ie7Check = (jQuery.browser.msie && (jQuery.browser.version < 8 || document.documentMode < 8));

	//$("#slideshowWindow").width(totalWidth);

	// Get a numbering system in place
	var slideShowNumbering = 1;
	$(".objSlideshowLI").each(function(){
		$(this).addClass("slideshow"+slideShowNumbering+"Pos");
		slideShowNumbering = slideShowNumbering+1;
	})


	/* Turn on the slideshow */
	$(".slideshowButton").click(function(){
		if (ie7Check == true){
			$("#"+iconsName).hide(300,function(){
				$("#slideshowIcons").show(300); $(".slideshowButton").hide(); $(".thumbnailsButton").show();
			})
		} else {
			$("#"+iconsName).slideUp(300,function(){
				$("#slideshowIcons").slideDown(300); $(".slideshowButton").hide(); $(".thumbnailsButton").show();
			})
		}
		currentMargin = 0; currentSlideshowNumber = 1;
	})

	/* Arrow designs */
	$(".arrowLeft").hover(function(){$(this).children("img").attr("src","http://mobia.org/assets/ss_arrow-l_on.png");}, function(){$(this).children("img").attr("src","http://mobia.org/assets/ss_arrow-l.png");})
	
	$(".arrowRight").hover(function(){$(this).children("img").attr("src","http://mobia.org/assets/ss_arrow-r_on.png");}, function(){$(this).children("img").attr("src","http://mobia.org/assets/ss_arrow-r.png");})

	
	// Set up some notifier dots //
	$("#slideShowToggler").append("<ul id=\"slideShowNotifier\"></ul>");
	var i=1;
	for (i=1;i<=numberOfObjects;i++) {
		$("#slideShowNotifier").append("<li class=\"notifier"+i+"\"><a href=\"#slideshow"+i+"\">Slideshow "+i+"</a></li>");
	}	

/*	if (ie7Check == true){
		$("a").click(function(){
			if($(this).attr("href").indexOf("#") != "-1"){
				var hash = this.href;
				hash = hash.replace(/^.*#/, '');
				$.historyLoad(hash);
				return false;
			}
		})
	}

			$.historyInit(pageload, "jquery_history.html");
			$(".historyEnabled").click(function(){
				var hash = this.href;
				hash = hash.replace(/^.*#/, '');
				$.historyLoad(hash);
				return false;
			});
*/

	$(".arrowRight, .arrowLeft").click(function(){
		setTimeout("pageload();",100);
		setTimeout("bindBehaviors();",700);
	})
	
	$(".eduHomeTable td").hover(function(){
		$(this).find("img").fadeTo("200",".6");
		$(this).find("h3").addClass("eduHovered");
	}, function(){
		$(this).find("img").fadeTo("200","1");
		$(this).find("h3").removeClass("eduHovered");
	})
	
	$(".firstParagraph p:first").css({"font-size":"15px","line-height":"130%"});
	$(".pad10 p:first").css({"margin-top":"0px"});

	$(".alertMessageWindow .closeThis").click(function(){$(".alertMessageWindow").fadeOut(1000);})
	

	$(".newsletterForm .submit").click(function(){
		if($(this).val() == "Join our email list"){
			return false;
		}
	})
	
	$("#pressImageSubmit").click(function(){
		if($(".requestFormUser").val() == "Name" || $(".requestFormUser").val() == "" || $(".requestFormPassword").val() == "Password" || $(".requestFormPassword").val() == "") {
			$(".requestFormError").show();
			return false;
		} else {$('#pressImageForm').submit();}
	})

	$(".calendarDaysNormal").find("td:last").addClass("borderRightCal");

});

function emailAdd(){$(".emailField").addClass("emailActive");}

function emailRemove(){$(".emailField").removeClass("emailActive");}


function addActiveClass(whatClass){$("."+whatClass).addClass("activeInput");}

function removeActiveClass(whatClass){$("."+whatClass).addClass("activeInput");}

var bindBehaviors = function() {
	//alert("hello");
	$(".activeSlide").hoverIntent(function(){
		if($(this).find(".imageCaption").attr("innerHTML").length > 10){$(this).find(".imageCaption").slideDown(200);}
	}, function(){$(this).find(".imageCaption").slideUp(200);})
}

function triggerSlideshow(){
	var numberOfObjects = $(".objSlideshowLI").size();
	if(numberOfObjects > 1){
		var hashChecker = location.hash;
		//alert(hashChecker);
		if(hashChecker == "") { window.location = "#slideshow1"; }
		pageload();
	} else {
		$(".slideShowStarter").hide();
		$(".arrowRight").hide();
		$(".arrowLeft").hide();
		$(".deadZoneLeft").hide();
		$(".deadZoneRight").hide();
		$("#slideshowArea ul").css({"left":"0px"});
		$("#objSlideshow1").find("img").fadeTo(100,1);
	}
}

function pageload() {
	var firstHash = location.hash.replace('#','');
	var newStartWidth = 205;
	var firstWidth = $("#objSlideshow1").width();
	newStartWidth = (824-firstWidth)/2-6;
	$(".slideShowStarter").css({"width":newStartWidth});
	var newSlideID = parseInt(firstHash.replace("slideshow",""));
	var offset = $("#objSlideshow"+newSlideID).position();
	var newSlideWidth = getSlideWidth(newSlideID);
	var curSlideWidth = $("#objSlideshow"+newSlideID).width();
	if (curSlideWidth == 0) { curSlideWidth = 400; }
	var fixSlideWidth = (824-curSlideWidth)/2;
	newSlideLocation = (offset.left-fixSlideWidth);
	//alert(offset.left + " and " + fixSlideWidth + " and " + newSlideLocation);
	$("#slideshowArea ul").animate({"left":newSlideLocation*-1});

	currentSlideshowNumber = newSlideID;
	//alert(currentSlideshowNumber);
	
	$(".arrowRight").attr("href","#slideshow"+(currentSlideshowNumber+1));
	$(".arrowLeft").attr("href","#slideshow"+(currentSlideshowNumber-1));
	if (currentSlideshowNumber == 1) {$(".arrowLeft").hide();} else {$(".arrowLeft").show();}
	if (currentSlideshowNumber == $(".objSlideshowLI").size()){$(".arrowRight").hide();} else {$(".arrowRight").show();}
	
	$(".objSlideshowLI").fadeTo(100,.5);
	$(".objSlideshowLI").removeClass("activeSlide");
	$("#objSlideshow"+currentSlideshowNumber).fadeTo(100,1);
	$("#objSlideshow"+currentSlideshowNumber).addClass("activeSlide");

	
	bindBehaviors();
}

function getSlideWidth(whatID){
	var whatIsWidth = $("#objSlideshow"+whatID).width();

}


