$(document).ready(function(){				  																
			$.fn.supersized.options = {  
				startwidth: 660,  
				startheight: 540,
				vertical_center: 1,
				slideshow: 0,
				navigation: 0,
				transition: 0, //0-None, 1-Fade, 2-slide top, 3-slide right, 4-slide bottom, 5-slide left
				pause_hover: 0,
				slide_counter: 1,
				slide_captions: 0
			};
	        $('#supersize').supersized();
	        $("#footer").css("z-index",10)

		/* Fade in the homepage */
		  $("#home #wrap").delay(1000).fadeIn("slow", function() {	
	  						$("#home #header li#header-step1").delay(300).animate({ 'left':'0' });
	  						$("#home #header li#header-step2").delay(700).animate({ 'left':'0' });
	  						$("#home #header li#header-step3").delay(1100).animate({ 'left':'0' });
	  						$("#home #header li#header-get-started").delay(1700).animate({ 'left':'0' });

		  });		
		  $("#home #footer").delay(1000).fadeIn("slow");

		// homepage select
		$(".event-over-message select").change(function() {
			if ($(this).attr("value")) {
				window.location = $(this).attr("value");
			}
		//	$(this).closest("form").submit();
		});
		
		// external links in new window
		$("a[rel=external]").live('click', function(e){window.open(this.href); e.preventDefault();});
		
		$("a[rel=external-sized]").live('click',function(e) {
			window.open(this.href, '_blank','height=460,width=500,alwaysRaised=yes');
			e.preventDefault();
		});
		
		/* Job descriptions */
		
		// set to closed (not done by default to allow for non-js)
		
		$(".company-positions ul li a.twirler").each(function() {		
			var parEl = $(this).parent();		
			var sibEl = $(this).siblings(".job-description");
			parEl.addClass("closed");
			parEl.closest(".company-listing").resize(function() {
				// force redraw, for IE
				$(this).css("display","none");
				$(this).css("display","block");			
			});
			
			$(this).toggle(function() {
	//			alert("clicked");			
	//			$(this).parent().children(".job-description").hide(); // hide in prep for fadeup
//				sibEl.fadeIn("slow");	
				parEl.removeClass("closed").addClass("open");
				parEl.closest(".company-listing").resize();
				// GA tracking for jobs
				var coName = $(this).closest(".company-listing").find(".company-name").html();
				var posName = $(this).text();
				_gaq.push(['_trackEvent', eventName + " > " + catName + " > " + coName, "Position Viewed ", posName]);
							
			}, function() {
//				sibEl.fadeOut("fast");	
				parEl.removeClass("open").addClass("closed");
			});
		});
		
		
		// modals 
		
		$(".ext-overlay-trigger").overlay({
			mask: { color: "#000000" },
			top:'center',
			onBeforeLoad: function() {
				var wrap = this.getOverlay().find(".contentWrap");
				wrap.load(this.getTrigger().attr("href"));
			}
		});		
		

		$(".schedule-trigger").overlay({
			mask: { color: "#000000" },
			top:'center',
			onBeforeLoad: function() {
				var wrap = this.getOverlay().find(".contentWrap");
				var coName = this.getTrigger().closest(".company-listing").find(".company-name").html();
				if (!coName) coName = "This Employer";
				var nowAdd = this.getTrigger().closest(".company-chat-info").find(".chat-now-container");
				if (nowAdd.length) { nowAdd = "<div class='chat-now-container'>" + nowAdd.html() + "</div>"; } else { nowAdd = ""; }
				
				wrap.html("<h1>Chat with " + coName + "</h1>" + 
				"<p>Chat is a great opportunity to learn more about positions and companies. You can even introduce yourself. Return during scheduled times to chat live with hiring companies!</p>" +	nowAdd + 			
				"<h2>Upcoming Chats</h2>" + "<ul>" + 				
				this.getTrigger().closest(".company-chat-info").find(".chat-schedule").html() + "</ul>");
				
			}
		});
		
		// video
//		$(".video-trigger").appendTo("body");
		if ($(".video").length) {
			$(".video").each( function() {
				flowplayer(
						$(this).attr("id")+"-player",
						{
							src:"/flash/flowplayer-3.2.5.swf", 
							wmode:'transparent'
						},
						{
							clip: { 
								url:$(this).find("span.url").html(),
								onFinish: function(clip,info) {
									$(".video").hide();
								}
							},
							plugins:  {
							    controls: null
							}, 
							play: { opacity:0 }

						}		
				);
				$(this).hide();				
			});
			
			// triggers
			$(".video-trigger a,.video-trigger-nav").click(function() {
				$($(this).attr("href")).show();
				var id = $(this).attr("href").split("#")[1] + "-player";
				$f(id).play();							
			});		
			
			$(".video .close").click(function() {
				$f(0).stop();
				$(this).parent(".video").hide();			
			});
					
		} // end if video
		
		// hovers for categories - NOTE: see ie.js for IE version
		if ($("#home").length) {
			$("#home .categories li.category").hoverIntent(function() {
				$("#footer").css("position","relative");			
				$(".category-overview").hide();
				$(this).find(".category-overview").show( 0, function() {		
					$(this).parent().animate({
						'opacity':1,
						'background-size': '80%',
						'-moz-background-size': '80%',
						'-webkit-background-size': '85% 75%'
					}, "350", function() {

						$(this).children(".category-overview").fadeIn("fast");
					});
				});
				
				
			},
			function() {
				$("#footer").css("position","fixed");
				$(this).animate({
						'background-size': '70%',
						'-moz-background-size': '70%',
						'-webkit-background-size': '80% 70%',				
						'opacity':'0.7'
					
				});
				$(this).children(".category-overview").hide();			
			});
		}		
		
		$("#home .categories li:nth-child(5n)").addClass("rightEdge");
		
	    /* Tabs */
	    // fix for map
		$(".company-listing .panes div:not(.map-canvas)").hide();

		// map workaround
	    $("ul.tabs").each(function() {
	    
			$(this).tabs($(this).closest(".company-listing").find("div.panes > div"), {
				effect:'slide',
	    		onClick: function() {
	    			var tab = this.getCurrentTab();
	    			
	    			tab.addClass("active");
					if(tab.hasClass("locations-tab") && !(this.getCurrentPane().hasClass("map-initialized") ) ){
						this.getCurrentPane().addClass("map-initialized");
						
						// get the ID for this one - assumes ID of company-locations-X
		    			var thisID = this.getCurrentPane().attr("id").substring(18);
						var toEval="init_map_"+thisID+"();";
						eval(toEval);
					}													
					if (tab.closest("ul").hasClass("initialized")) {
						var parEl = tab.closest(".company-listing");												
						var coName = parEl.find(".company-name").text();
						if (!coName) coName = "ALL COMPANIES";
	//					var catName = $(".category-header").text();					
						_gaq.push(['_trackEvent', eventName + " > " + catName + " > " + coName, "Tab Clicked: " + tab.text(), catName]);
					} else {
						tab.closest("ul").addClass("initialized");
					}
														
		   		}
		   	});
		  

		});
		
		$(".tabs").each(function() {		
			$(this).lavaLamp({ startItem: "0",autoReturn:true,setOnClick:true,fx: "easeOutBack", speed: 700});

			$(this).children("li").hover(function() {	
				// disable "current" on siblings			
				$(this).siblings().removeClass("current");				
				$(this).siblings().find("a").removeClass("current");				
			}, function() {
				$(this).removeClass("current");
			});
			
			// and force it back on on hover
//			$(this).find("li a").click(function() { $(this).addClass("current"); });

		});		
/*		$(".tabs a").mouseenter(function() { $(this).click(); });		 */
		
		// cross-fade banner ads
		if ($("#banner-ads").length) {
			$("#banner-ads").cycle({
				delay:1000,
				timeout:5000,
				pause:1,
				fx:'fade'
			});
		}		
		
		$(".location-list li a").click(function(e) {
			$(this).parent("li").toggleClass("open");
			e.preventDefault();
		});
					

		$(".apply-button").click(function(e) {
		
			var coName = $(this).closest(".company-listing").find(".company-name").html();
			if (!coName || coName=='null') { 
				coName = "Main Apply Button"; 
				_gaq.push(['_trackEvent', eventName + " > " + catName + " > " + coName, "Job Application"]);
			} else {			
				var posName = $(this).closest("li").find(".twirler").text();

				_gaq.push(['_trackEvent', eventName + " > " + catName + " > " + coName, "Job Application", posName]);
			}
			
		});
		
		// track banners
		$(".banner-ad a").click(function(e) {

			e.preventDefault();
			var evName = $(this).closest(".company-listing").find(".company-name").html();
			var evURL = $(this).attr("href").substring(0,50);
			_gaq.push(['_trackEvent', eventName + " > " + catName + " ALL COMPANIES", "Ad Click", $(this).parent().attr("id") + ": " + evURL]);
			if (!$(this).attr("rel")) { // doesn't load up rel=external etc.)
				setTimeout('window.open("'+ $(this).attr("href") + '")',100);
//			    setTimeout('document.location = "' + $(this).attr("href") + '"', 100);
			}
			
//			_gaq.push(['_trackEvent', pageLink, "Banner Ad Click", $(this).parent().attr("id")]);			
		});
				
			  (function() {
			    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
			    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';			    
			    var s = document.getElementsByTagName('script')[0]; 			    
			    s.parentNode.insertBefore(ga, s);			    
			  })();
		

		// Footer links
		$("#footer a").click(function(e) {
			e.preventDefault();
			var evURL = $(this).attr("href").substring(0,50);
			_gaq.push(['_trackEvent', eventName + " > " + catName + " ALL COMPANIES", "Footer Link Click", evURL]);

			if (!$(this).attr("rel")) { // doesn't load up rel=external etc.
			    setTimeout('document.location = "' + $(this).attr("href") + '"', 100);
			}			
		
		});		
				
		// Other trackable links
		$("a.trackable,a.external").click(function(e) {
			e.preventDefault();
			var evURL = $(this).attr("href").substring(0,50);
			_gaq.push(['_trackEvent', eventName + " > " + catName + " ALL COMPANIES", "External Link Click", evURL]);
			
			if (!$(this).attr("rel")) { // doesn't load up rel=external etc.
			    setTimeout('document.location = "' + $(this).attr("href") + '"', 100);
			}			
		});
	
});
