function isAdmin()
{
	var winUrl = new String(window.location.href);
	if (winUrl.match('admin=1') != null)
		return true;
	return false;	
}


function setAdminInterface()
{
	jQuery('#TopNav a')
		.add('#Testimonials a:first')
		.each(function()
				{
					var adminLink = jQuery(this);
					adminLink.attr('href', adminLink.attr('href') + '?admin=1')
				});
	
	jQuery('#Content .InnerContent')
		.add('#Content .InnerContent ul.divisionSublinks ul')
		.css({
			 	visibility: 'visible',
				display: 'block'
			 });
		
	jQuery('#Testimonials, #testimonials').css('height', 'auto');
	jQuery('.infoZone').css({display: 'block', height: 'auto'});	
	jQuery('.infoBubble').css({position: 'static', visibility: 'visible', margin: 'auto', background: 'none', border: '1px solid #CCC'});
}

function resizeWrappers(){
	jQuery('#Content').css('height', '548px');
}

// the custom popups
function initTIpopups()
{
	jQuery.extend(window, {customPopups: {}});
	var ContentSection = jQuery('#Content');
	var popupLinks = jQuery('#TopNav a, a.popupTrigger');
	popupLinks
		.each(function(index)
			{
				var ind = index;
				var triggerLink = jQuery(this);
				triggerLink.click(function()
								  {
									//TIslideshow.stop();
									//TIslideshow.showMaskLayers();
									//TIslideshow.loadSlide(0);
									closeCustomPopups();
								  });
				
				window.customPopups['popup' + ind] = new dc_Popup(triggerLink, {
																		popupIframeName: 'popup' + ind,
																		popupWidth: 893, 
																		popupHeight: 492, 
																		popupBackground: "#FFFFFF",
																		popupLeft:  '0px', 
																		popupTop: '58px',
																		showPopupMask: false,
																		popupParentNode: jQuery('#Content')
																		});
			});	
}

// closes all custom popups
function closeCustomPopups()
{
	if (window.customPopups)
	{
		for (var i in window.customPopups)
			window.customPopups[i].off();
	}
}

// initializes the subnav links
function initContentSubnavLinks()
{
	var secLevNavs = jQuery('#Content ul.divisionSublinks ul');
	secLevNavs.css('display', 'none');
	var ContentSublinks = jQuery('#Content ul.divisionSublinks>li>a').not('.directLink');
	ContentSublinks
		.click(function(){
					var thisLink = jQuery(this);
					secLevNavs.css('display', 'none');
					thisLink.next().css('display', 'block');
					return false;
				})
}

function rotateTestimonials()
{
	jQuery('#testimonials')
		.cycle({ 
			fx:     'scrollDown',
			pause: 1, 
			timeout: 12000, 
			delay:  -1000
		})	
}

jQuery(function(){
	if (isAdmin())
		setAdminInterface();
	else
	{
		initContentSubnavLinks();
		resizeWrappers();
		TIslideshow = new Slideshow();
		TIslideshow.init();
		initTIpopups();
		
		setTimeout(rotateTestimonials, 2000);
	}
})