var global = new Object();

/*****************************************************
*   INIT VARIABLES                                   *
*                                                    *
******************************************************/
//Init global variables
global.baseUrl = 'http://www.ksand.com/';
global.animSpeed = 500;
global.temp = 0;
global.tempHref = '';
global.pageType = '';
global.scrollToCallback = false;
global.scrollToPage = '';
global.moreMenuHover = false;
global.moreLinkHover = false;

//Init variables for topPanel
global.topPanel = new Object();
global.topPanel.opacity = 0.95;
global.topPanel.height = 600; //in px
global.topPanel.width = 750; //in px
global.topPanel.pxToClose = -700;

//Init variables for the scrolling middle
global.middle = new Object();
global.middle.scrollDistance = 1000;
global.middle.menuInterval = 5000;
global.middle.menuCount = 0;
global.middle.menuCurrent = 0;

//Init variables for featured slideshow
global.featured = new Object();
global.featured.interval = 10000;
global.featured.timer = '';

//Init variables for the ourWork Flip2D section
global.ourWork = new Object();
global.ourWork.animSpeed = 300;
global.ourWork.animating = false;

//Offsets for Flip2D images
global.ourWork.left = 40;
global.ourWork.top = 20;
global.ourWork.width = 30;
global.ourWork.height = 30;

//Init topPanelContent object
global.tpc = new Object();
global.tpc.to = '3102 Berger St. Allentown, PA. 18103-7014'; //Used for contact section (Google Maps)

//Init footer object
global.footer = new Object();
global.footer.hover = false;

//Set hover settings
$.event.special.hover.delay = 50; 
$.event.special.hover.speed = 50; 

/*****************************************************
*   MORE MENU READY FUNCTION                         *
*                                                    *
******************************************************/
/*
The below code is like a document ready except we just want to see when the menu is ready.
This kicks off before document ready so things move faster. Note we are waiting for
headerDropdownContainer ready instead of headerDropdownLink ready because the link comes
first in the DOM. If we wait for that and the container is not loaded we will hit an exception
*/
$('div#header div#headerContent div#headerDropdownContainer').ready(function(){
	global.initHeader();
});

/*****************************************************
*   DOCUMENT READY FUNCTION                          *
*                                                    *
******************************************************/

$(document).ready(function(){
	//global.scrollHash(); //Doesnt work yet
	global.init();
	global.initMiddle();
	global.initDetect();
	global.initClasses();
	global.initFooter();
	global.initTopPanel();
	global.initContactUs();
	global.goBack();
	
	//Init timer for featured slideshow
	global.featured.current = parseInt($('#hidFeaturedStart').val());
	global.featured.count = parseInt($('#hidFeaturedCount').val());
	global.featured.timer = setInterval('global.featuredSlideshow()', global.featured.interval);
	
	/*$("img.rollover").hover(
	 function()
	 {
	  this.src = this.src.replace("_off-trans","_on-trans");
	 },
	 function()
	 {
	  this.src = this.src.replace("_on-trans","_off-trans");
	 }
	);*/
	
	/*******Disables links in tag cloud on the homepage********/
	$('div#homeTagCloud li a[href="#"]').click(function(){ return false; }); 
});

/******************************************************
*   INIT FUNCTION                                     *
*   Description: Handles immediate initiation         *
******************************************************/
global.init = function(){
	//Prepend all topPanel content into the headerContent div (currently in footer for faster loading)
	$('#headerContent').prepend('<div id="topPanel" class="roundedBottom orange whiteText">' + $('#topPanelTemp').html() + '</div>');
	$('#topPanelTemp').remove(); //Remove the old topPanel
}
  
/***********************************************************************
*   SCROLL HASH FUNCTION   (Doesnt work yet)                           *
*   (Code borrowed from http:                                          *
*   //www.learningjquery.com/2007/09/animated-scrolling-with-jquery-12 *
*   Since my code didnt work)                                          *
************************************************************************/
global.scrollHash = function(){
	$('a[href*=#]').click(function() {
		 if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
		 && location.hostname == this.hostname) {
			 var $target = $(this.hash);
			 $target = $target.length && $target
			 || $('[name=' + this.hash.slice(1) +']');
			 if ($target.length) {
			var targetOffset = $target.offset().top;
			$('html,body')
			.animate({scrollTop: targetOffset}, 1000);
				return false;
			 }
		 }
  });
}

/*****************************************************
*   INIT HEADER FUNCTION                             *
*                                                    *
******************************************************/
global.initHeader = function(){
	//Now we init the hover function for the more link
	$('a#headerDropdownLink').click(function(){
		if ($('div#headerDropdownContainer').is(':visible')){
			$('div#headerDropdownContainer').slideUp('medium');
		} else {
			$('div#headerDropdownContainer').slideDown('medium');
		}
	});
}


/*****************************************************
*   INIT TOPPANEL FUNCTION                           *
*                                                    *
******************************************************/
global.initTopPanel = function(){
	//Create dark, transparent background
	$('body').prepend('<div id="lightbox_bg"></div>');
	//Add properties to lightbox overlay
	$('#lightbox_bg').css({ opacity: 0.75, width: $(document).width() + 'px', height: $(document).height() + 'px' });
	$('#lightbox_bg, a#tp_closeLabel, a#tp_closeLabel2').click(function(){ //Init close on lightbox background click and close button click
		global.topPanel.close(); //Close the topPanel
	});

	//Init links on panel
	$('div#header div#headerContent ul#headerMain li a').each(function(){ //Loop through all links on the headerMain menu
		var tempName = $(this).attr('rel'); //Get the text inside (e.g. Our Work, About, Contact etc.
		tempName = tempName.replace(/ /g, ''); //Remove any spaces so Our Work would become OurWork. This is the name of the div.
		$(this).attr('href', '#').click(function(){ //Make the href of the link to be # and add function when clicked
			if ($(this).attr('id')!='') {
				var id = $(this).attr('id');
				id = id.replace('Link', '');
				$('.activeAbout').removeClass('activeAbout').parent().removeClass('about_active');
				$('div.about_active').removeClass('about_active').hide();
				$('#tpc_about_leftNav ul li a:contains(' + id + ')').addClass('activeAbout').parent().addClass('about_active');
				$('#tpc_about_content #about' + id).addClass('about_active').show();
			}
			global.topPanel.open(tempName); //Open the topPanel
			
		});
	});
	
	//Init sites for Flip2D
	var siteCount = 0;
	$('#tpc_ourWork_sites a[rel=lightbox] img').each(function(i){ //Loop through all sites
		if ($(this).css('zIndex')<=3){ //If it is more than the sixth we hide it
			$(this).css({ display: 'none' });
		}
		$(this).css({ opacity: 0.80 }).hover(
			function(){
				$(this).animate({ opacity: 1 }, 500);
			},
			function(){
				$(this).animate({ opacity: 0.80 }, 500);
			}
		);
		siteCount++;
	});
	$('#tpc_ourWork_count').text(siteCount); //Set count text to be the number of sites
	
	//Init lightboxes for Flip2D
	$('a[rel=lightbox] img.active').parent().click(function(){ //When a lightbox enabled image is clicked...
		global.topPanel.close(); //Close the topPanel
	}).lightBox();
	
	//Init features for about section
	$('#tpc_about_leftNav ul li a').click(function(){
		$('a.activeAbout').removeClass('activeAbout');
		$(this).addClass('activeAbout');
		var newDiv = $(this).attr('href').match(/(#.*)/)[0];
		$('#tpc_about_leftNav ul li.about_active').removeClass('about_active');
		$(this).parent().addClass('about_active');
		$('#tpc_about_content div.about_active').removeClass('about_active').fadeOut(global.animSpeed, function(){
			$('#tpc_about_content div' + newDiv).addClass('about_active').fadeIn('slow');
		});
		return false;
	});
	$('#prevBtn').click(function(){
		global.ourWork.prev();
	});
	$('#nextBtn').click(function(){
		global.ourWork.next();
	});
}


/*****************************************************
*   INIT MIDDLE FUNCTION                             *
*                                                    *
******************************************************/
global.initMiddle = function(){
	//Init topNav Links
	/* NOTICE
		 This has been changed on 7/27/09 by Chuck Hriczko
		 We changed the way the system works. Instead of clicking to navigate to the next slide
		 the system will automatically navigate. Simple timed scroller.
	*/
	// OLD CODE
	/*$('div#topNav div.center ul:first-child li a').each(function(i){
		var curHref = $(this).attr('href'); //Get current href
		var curHrefArray = new Array();
		curHrefArray = curHref.split('#'); //Make array containing the url and the has (without the #)fs
		$(this).attr('href', '#' + curHrefArray[1]); //Change href to hash only (with #)
	});
	
	//Set up clicks for middle menu
	$('div#topNav ul li a').click(function(){
		global.temp = $(this).attr('href');
		global.tempHref = global.temp.replace('#', '');
		global.scrollToPage = slideLocations[global.tempHref];
		$('div#topNav ul li.active').removeClass('active');
		$(this).parent().addClass('active');
		$('div#middle div.center').scrollTo($(global.temp), global.animSpeed, {axis:'x', onAfter: function(i){
			//Callback for scrollto
			//The callback seems to be calling multiple times so we implement a switch to tell if it has run
			if (global.scrollToCallback==false){
				if (global.scrollToPage=='212/Applications'){
					window.location = global.baseUrl + 'pages/get/' + global.scrollToPage;
				} else {
					window.location = global.baseUrl + 'pages/services/' + global.scrollToPage;
				}
				global.scrollToCallback = true;
			}
		}});
		
		return false; //Make sure the page doesnt move to the anchor when clicked
	});
	
	$('div#topNavStuff div.middle_div a').click(function(){
		var href = $(this).attr('href');
		global.tempHref = href.replace('#', '');
		global.scrollToPage = slideLocations[global.tempHref];
		$('div#middle div.center').scrollTo($(href), global.animSpeed, {axis:'x', onAfter: function(i){
			//Callback for scrollto
			//The callback seems to be calling multiple times so we implement a switch to tell if it has run
			if (global.scrollToCallback==false){
				if (global.scrollToPage=='212/Applications'){
					window.location = global.baseUrl + 'pages/get/' + global.scrollToPage;
				} else {
					window.location = global.baseUrl + 'pages/services/' + global.scrollToPage;
				}
				global.scrollToCallback = true;
			}
		}});
		return false;
	});*/
	
	//NEW CODE
	$('.slide').each(function(i){ //First loop through all slides and get number
		global.middle.menuCount++;	
	});
	setInterval(function(){
		if (global.middle.menuCurrent==(global.middle.menuCount)) global.middle.menuCurrent = 0;
		$('div#middle div.center').scrollTo($('#slide_' + global.middle.menuCurrent), global.animSpeed, {axis:'x'});
		global.middle.menuCurrent++;
	}, global.middle.menuInterval);
}

/*****************************************************
*   INIT FEATURED SLIDESHOW                          *
*                                                    *
******************************************************/
global.featuredSlideshow = function(){
	$('#featuredContent' + global.featured.current).fadeOut(global.animSpeed, function(){
		if (global.featured.current==global.featured.count-1){
			global.featured.current = 0;
		} else {
			global.featured.current++;
		}
		
		$('#featuredContent' + global.featured.current).fadeIn(global.animSpeed);
	});	
}


/*****************************************************
*   OUR WORK NEXT BUTTON FUNCTION                    *
*                                                    *
******************************************************/
global.ourWork.next = function(){
	var size = $('div.scrollingItemParent').size();
	var end = size - 1;
	var id = $('.scrollingItem.active').parent().attr('id');
	id = parseInt(id.replace('scrollingItem', ''));
	if(id<end){
		id++;
		$('.scrollingItem.active').removeClass('active');
		$('#scrollingItem' + id).children('img').addClass('active');
		$('#viewport').scrollTo($('#scrollingItem' + id), 500, {axis: 'x'});	
	}
	else if(id==end) {
		id = 0;
		$('.scrollingItem.active').removeClass('active');
		$('#scrollingItem' + id).children('img').addClass('active');
		$('#viewport').scrollTo($('#scrollingItem' + id), 500, {axis: 'x'});
	}
}

/*****************************************************
*   OUR WORK PREVIOUS BUTTON FUNCTION                *
*                                                    *
******************************************************/
global.ourWork.prev = function(){
	var size = $('div.scrollingItemParent').size();
	var end = size - 1;
	var id = $('.scrollingItem.active').parent().attr('id');
	id = parseInt(id.replace('scrollingItem', ''));
	if(id>0){
		id--;
		$('.scrollingItem.active').removeClass('active');
		$('#scrollingItem' + id).children('img').addClass('active');
		$('#viewport').scrollTo($('#scrollingItem' + id), 500, {axis: 'x'});	
	}
}

/*****************************************************
*   OUR WORK SKIP TO FUNCTION  (WORK IN PROGRESS!!!) *
*                                                    *
******************************************************/
global.ourWork.skipTo = function(siteNum){
	var i = parseInt($('#tpc_ourWork_counter').text());
	while (i<siteNum){
		//Now we work on all the other images
		var allImgs = $('div#tpc_ourWork_sites a img'); //Grab all images
		allImgs = $.makeArray(allImgs); //Turn them into an array
		allImgs.reverse(); //Reverse the array
		var imgCount = allImgs.length;
		var imgDisplay = imgCount - 6;

		$(allImgs).each(function(){ //Loop through all images
			var curzIndex = $(this).css('zIndex'); //Get current zIndex
			if (curzIndex==imgCount){
				curzIndex = 1;
				var left = global.changeSign(global.ourWork.left*imgCount);
				var top = global.changeSign(global.ourWork.top*imgCount);
				var width = 320-(global.ourWork.width*imgCount);
				var height = 280-(global.ourWork.height*imgCount);
				$(this).hide();
				$(this).css({ display: 'none', left: left + 'px', top: top + 'px', width: width + 'px', height: height + 'px', zIndex: '1' }); //Make currently active image have the lowest zIndex (last one)
			} else {
				curzIndex++; //Increment by one
				var left = global.changeSign(global.ourWork.left*(imgCount-curzIndex));
				var top = global.changeSign(global.ourWork.top*(imgCount-curzIndex));
				var width = 320-(global.ourWork.width*(imgCount-curzIndex));
				var height = 280-(global.ourWork.height*(imgCount-curzIndex));
				if (curzIndex>imgDisplay){
					$(this).css({ display: 'none', left: left + 'px', top: top + 'px', width: width + 'px', height: height + 'px', zIndex: curzIndex }, global.animSpeed);
				} else {
					$(this).css({ display: 'block', left: left + 'px', top: top + 'px', width: width + 'px', height: height + 'px', zIndex: curzIndex }, global.animSpeed);
				}
			}
	
			if (curzIndex==imgCount){ //If we are on the current image
				thisId = $(this).attr('id'); //Get current id
				thisId = thisId.replace('tpc', ''); //Strip tpc out of id. E.g. If I id = tpc0 then it would be 0
				$('#tpc_ourWork_counter').text(parseInt(thisId)+1);	//Change counter to be current id
				$(this).parent().lightBox(); //We enable the lightbox
				$('.tpc_ourWork_siteDescription_active').removeClass('tpc_ourWork_siteDescription_active').hide();
				$('#tpc_ourWork_siteDescription' + thisId).addClass('tpc_ourWork_siteDescription_active').show();
			}
		});
		i++; //Increment counter for while loop
		if (i>imgCount) i = 0;
	}
}

/*****************************************************
*   INIT CONTACT US FUNCTION                         *
*                                                    *
******************************************************/
global.initContactUs = function(){
	//Init captcha for contact page


	//Init function for submit button click
	$('#tpc_contact_form_main a').click(function(){
		$('#tpc_contact_form_main').fadeOut('slow', function(){
			$('div#tpc_contact_form_busy').fadeIn('slow', function(){
				var frmSerialized = $('#tpc_contact_form_main form').serialize();
				$.ajax({
					url: '/pages/contact/',
					type: 'post',
					data: frmSerialized,
					success: function(msg){
						if (msg=='success'){
							$('#tpc_contact_form_busy').fadeOut('slow', function(){
								$('#tpc_contact_form_success').fadeIn();
							});
						} else {
							$('#tpc_contact_form_busy').fadeOut('slow', function(){
								$('#tpc_contact_form_msg').css({ color: 'red' }).html(msg);
								$('#tpc_contact_form_main').fadeIn();
							});
						}
					}
				});
			});
		});
		return false;
	});
	
	//Init contact success go back link
	$('#tpc_contact_form_success a').click(function(){
		$('#tpc_contact_form_success').fadeOut('slow', function(){
			$('#tpc_contact_form_msg').css({ color: '#fff' }).html('Have a question? Complete the form below.');
			$('#tpc_contact_form_main').fadeIn('slow');
		});
		return false;
	});
	
	/*//Init Google Maps
	map = new GMap2(document.getElementById('map_canvas'), { //Create a new maps object which will show up in the 'map_canvas' div
		size: new GSize(300, 230) //You really need an explanation?
	});
	geocoder = new GClientGeocoder(); //Create a new geocoder object. This takes a string address and converts it to lat/long
	geocoder.getLatLng(global.tpc.to, function(point){ //This is the function that does this the above
			map.setCenter(point, 13); //Center the map on the new point with a zoom of 13
			map.addControl(new GSmallMapControl());
			map.addControl(new GMapTypeControl());
			map.addOverlay(new GMarker(point));
			gmapsReady = true; //Let the rest of the page know that the we are ready
		}
	);
	$(document).bind('unload', function(){ //To prevent memory leaks when the document is unloaded we unload the Google vars
		GUnload();
	});*/
}

/*****************************************************
*   GET DIRECTIONS FUNCTION                          *
*                                                    *
******************************************************/
global.getDirections = function(from){
	if (gmapsReady==true){ //If gMaps is ready this variable will be true
			$('#directionsPanel').html(''); //Empty the directionsPanel
			var directionsPanel = document.getElementById('directionsPanel'); //Get a handle on the directions panel
			var directions = new GDirections(map, directionsPanel); //Get the directions object
			directions.load('from: ' + from + ' to: ' + global.tpc.to, {travelMode:G_TRAVEL_MODE_DRIVING}); //Load the directions
			$('#topPanelContent_Contact div.active').slideUp(global.animSpeed, function(){
				$('#tpc_contactDirections').slideDown(global.animSpeed);
			});
	}
}

/*****************************************************
*   INIT FOOTER FUNCTION                             *
*                                                    *
******************************************************/
global.initFooter = function(){
	$('#module_container').hover(
		function(){
			$('#module_speech_bubble').fadeIn(global.animSpeed)
		},
		function(){
			$('#module_speech_bubble').fadeOut(global.animSpeed);
		}
	);
	
	$('#module_speech_bubble').hover(
		function(){
		},
		function(){
			$('#module_speech_bubble').fadeOut(global.animSpeed);
		}
	);
}


/*****************************************************
*   CHANGE SIGN FUNCTION                             *
*                                                    *
******************************************************/
global.changeSign = function(num){
	return parseInt(num * -1);
}

/*****************************************************
*   INIT CLASSES FUNCTION                            *
*                                                    *
******************************************************/
global.initClasses = function(){
	//Finds all links with the class jsPopup and makes a popup window with the href inside
	$('a.jsPopup').each(function(){
		var tempHref = $(this).attr('href');
		$(this).attr('href', '#').click(function(){
			window.open(tempHref, 'jsPopup', 'width=640, height=480, scrollbars=1');
			return false;
		});
	});
	
	//Finds all links with a class of jsGoBack and creates a back button out of it
	$('a.jsGoBack').click(function(){
		history.go(-1);
		return false;
	});
	
	
	//Finds all links with a class of jsOurWork and makes the screen slide up and our work window slide down
	$('a.jsOurWork, a[href=#jsOurWork]').click(function(){
		global.scrollToCallback = false;
		/*var id = $(this).attr('href');
		id = parseInt(id.replace('#jsOurWork', ''));
		global.ourWork.skipTo(id);*/
		$(this).attr('href', '');
		$(document).scrollTo($('#headerMain'), global.animSpeed, {axis:'y', onAfter: function(){
			if (global.scrollToCallback==false){
				global.topPanel.open('OurWork');
				global.scrollToCallback = true;
			}
		}});
		return false;
	});
	
	//Finds all links with a class of jsAbout and makes the screen slide up and about window slide down
	$('a.jsAbout, a[href=#jsAbout]').click(function(){
		global.scrollToCallback = false;
		$(this).attr('href', '');
		$(document).scrollTo($('#headerMain'), global.animSpeed, {axis:'y', onAfter: function(){
			if (global.scrollToCallback==false){
				global.topPanel.open('About');
				global.scrollToCallback = true;
			}
		}});
		return false;
	});
	
	
	//Finds all links with a class of jsContact and makes the screen slide up and contact window slide down
	$('a.jsContact, a[href=#jsContact]').click(function(){
		global.scrollToCallback = false;
		$(this).attr('href', '');
		$(document).scrollTo($('#headerMain'), global.animSpeed, {axis:'y', onAfter: function(){
			if (global.scrollToCallback==false){
				global.topPanel.open('Contact');
				global.scrollToCallback = true;
			}
		}});
		return false;
	});
	
	//Finds all uls with horizontalNav or noBullets and kills bg image (have to do this because of ie7.js sideeffect)
	if ($('ul.noBullets li, ul.horizontalNav li').css('background')=='http://www.ksg3.com/newsite/images/small_text_bullet-trans.png'){
		$('ul.noBullets li, ul.horizontalNav li').css('background', 'none');
	}
	
	//Take all links with these classes and give them a target _blank attribute
	$('.externalLink').attr('target', '_blank');
}

/*****************************************************
*   INIT DETECT FUNCTION                             *
*                                                    *
******************************************************/
global.initDetect = function(){
	if ($.browser.mozilla){
		$('div#topPanel div#topPanelContent div#topPanelContent_About div#tp_content div#tpc_about_content div#jobPostingsList table tr td.left').css({ marginTop: '-1px' });
	}
}

/*****************************************************
*   PREFETCH FUNCTION                                *
*   Description: Prefetches common files to make     *
* 	             site load faster                    *
******************************************************/
global.prefetch = function(){	
	//Caches topNav pages for faster loading later
	/*$.ajax({ url:"/pages/services/190/", cache:true, dataType:"text" });
	$.ajax({ url:"/pages/services/211/", cache:true, dataType:"text" });
	$.ajax({ url:"/pages/services/212/", cache:true, dataType:"text" });
	
	//Caches featured pages
	$.ajax({ url:"/pages/get/227/", cache:true, dataType:"text" });
	$.ajax({ url:"/pages/get/213/", cache:true, dataType:"text" });
	$.ajax({ url:"/pages/get/228/", cache:true, dataType:"text" });
	$.ajax({ url:"/pages/get/229/", cache:true, dataType:"text" });
	$.ajax({ url:"/pages/get/239/", cache:true, dataType:"text" });
	 
	//Caches Javascripts
	$.ajax({ url:"/scripts/services.js", cache:true, dataType:"text" });
	
	//Caches Styles
	$.ajax({ url:"/styles/sub.css", cache:true, dataType:"text" });
	$.ajax({ url:"/styles/sub.ie.css", cache:true, dataType:"text" });
	$.ajax({ url:"/styles/sub.ie6.css", cache:true, dataType:"text" });
	
	//Caches Images
	global.prefetchDir('/images/middle_menu/');
	global.prefetchDir('/images/screenshots/');
	global.prefetchDir('/images/icons/');*/
}

/********************************************************
*   PREFETCHDIR FUNCTION                                *
*   Description: Prefetches common entire directory     *
* 	             site load faster                       *
********************************************************/
global.prefetchDir = function(dir){
	$.ajax({
		url: '/pages/dirList/',
		type: 'POST',
		dataType: 'json',
		data: 'dir=' + dir,
		success: function(json){
			for(i=0; i<json.count; i++){ //Loop through returned array
				$.ajax({ url: dir + json.files[i].file, cache:true, dataType:"text" }); //Prefetch file
			}
		}
	});
}

/*****************************************************
*   Function Name: global.topPanel.open()            *
*   Description: Opens the topPanel                  *
*   Params:                                          *
*   	contentId - DOM Id of the content to load      *
******************************************************/

global.topPanel.open = function(contentId){
	if ($('#topPanel').css('top')!='0'){ //If topPanel's top equals 0 then it is already open. If it's not, we continue
		clearInterval(global.featured.timer); //Stop slideshow while topPanel is down
		$('#lightbox_bg').fadeIn(global.animSpeed, function(){ //Show overlay
			$('#topPanelContent div.active').removeClass('active').hide(); //Remove the active class from any content and hide all content
			if ($.browser.msie){ //IE has some zIndex issues that must be fixed through javascript
				$('#topNav ul, a.check_mark img, #igee_burst').hide();
			}
			$('#topPanel').animate({ top: '0' }, global.animSpeed, function(){ //Finally, we animate topPanel's top to 0 (open)
				$('#topPanelContent_' + contentId).addClass('active').show(); //And now we add the active class to the relevant content and show it
			});
		}); //Fade in the overlay
	}
}

/*****************************************************
*   Function Name: global.topPanel.close()           *
*   Description: Closes the topPanel                 *
*   Params:                                          *
*   	contentId - DOM Id of the content to load      *
******************************************************/

global.topPanel.close = function(){
	if ($('#topPanel').css('top')!=global.topPanel.pxToClose){ //If topPanel's top equals -700px then it is already closed. If it's not, we continue
		$('#topPanelContent div.active').removeClass('active').hide(); //Remove the active class from any content and hide all content
		$('#topPanel').animate({ top: global.topPanel.pxToClose + 'px' }, global.animSpeed, function(){ //Finally, we animate topPanel's top to closed
			$('#lightbox_bg').fadeOut(global.animSpeed, function(){ //Hide overlay
				global.featured.timer = setInterval('global.featuredSlideshow()', global.featured.interval); //Start interval back up for featured slideshow
			});
		});
		if ($.browser.msie){ //IE has some zIndex issues that must be fixed through javascript
			$('#topNav ul, a.check_mark img, #igee_burst').show();
		}
	}
}

/*****************************************************
*   Function Name: global.initTwitter  ()            *
*   Description: Inits the Twitter feed              *
*                                                    *
******************************************************/

global.initTwitter = function(){
	$.jTwitter('ksg3interactive', function(userdata){
		console.log(userdata);
	});
}

global.goBack = function(){
	$('a.goBack').attr('href', 'javascript:history.back()');
}


