function reset_content_width() {
	$('.scroll').each( function() {
		var panel_width = $(this).width();
		var panel_count = $(this).find('.panel').size();
		$(this).find('.scrollContainer').css({'width' : (panel_count * (panel_width))});
		$(this).find('.panel').each( function() { $(this).css({'width' : (panel_width - 30), 'padding-right' : 0, 'padding-left' : 20}); });
	});

	$('.home .scroll').each( function() {
		var panel_width = $(this).width();
		var panel_count = $(this).find('.panel').size();
		$(this).find('.scrollContainer').css({'width' : (panel_count * (panel_width))});
		$(this).find('.panel').each( function() { $(this).css({'width' : (panel_width - 20), 'padding-right' : 0, 'padding-left' : 10}); });
	});
	
	$('.container').each( function() {
		var panel_width = $(this).width();
		var panel_count = $(this).find('.leader').size();
		$(this).find('.leader').each( function() { $(this).css({'width' : (panel_width - 40), 'padding-right' : 20}); });
	});
	return 1;
}


$(window).resize( function() {
	if (is_mobile()) {
		reset_content_width();
	}
});


$(window).load(function() {
						   
	//Hide (Collapse) the toggle containers on load
	$(".toggle_container").hide(); 

	//Slide up and down on click
	$("#trigger").click( function(e){
		e.preventDefault(); 
		$(".toggle_container").slideToggle("slow");
	});


	//Switch the "Open" and "Close" state per click
	$("#trigger").toggle(function(){
		$(this).addClass("active");
		}, function () {
		$(this).removeClass("active");
	});


	$('.tooltip').click( function(e) { e.preventDefault(); });

	$('#wrapper').addClass( ((is_mobile()) ? "mobile": "desktop") );

	if (!is_mobile()) {
		
		equalHeight($(".promo"));
		
		$("a#single_image").fancybox();
		$("a.grouped_elements").fancybox();
		
		$("a.inlinepanel").fancybox({
			'modal':true
		});	
			
		$("a#flash_leaderboard_zoom").fancybox({
			'padding':0,
			'width':728,
			'height':90,
			'autoScale':false,
			'transitionIn':'none',
			'transitionOut':'none'
		});
		$("a#flash_mpu_zoom").fancybox({
			'padding':0,
			'width':300,
			'height':250,
			'autoScale':false
		});
		$("a#flash_wide_zoom").fancybox({
			'padding':0,
			'width':600,
			'height':405,
			'autoScale':false
		});

		
	} else { // end not mobile

		reset_content_width();

		$("#trigger").remove();
		$("#flashcontent").html('').append("<div class='mobile-logo' />").addClass('mobile').fadeIn();

		$("ul#menu").hide().append('<li><a id="trigger_mob" class="nav" href="#">Contact</a></li>').fadeIn();

		$("#trigger_mob").unbind().bind('click', function(e) { e.preventDefault(); $(".toggle_container").slideToggle(); });

		$("a#single_image, a.grouped_elements, a#flash_leaderboard_zoom, a#flash_mpu_zoom, a#flash_wide_zoom").click(function(e){e.preventDefault()});		

		

	} // end is mobile



/*
	$("a.group").fancybox({
		'transitionIn'	:	'elastic',
		'transitionOut'	:	'elastic',
		'speedIn'		:	600, 
		'speedOut'		:	200, 
		'overlayShow'	:	false
	});
*/


});


// header height adjustment //
//function toggleheaderheight() {
//	$("#menu").slideToggle('fast', function() {
//		var menu_toggle = ( $(this).is(":visible") ) ? true : false;
//		var menu_height = 0;
//		$(this).find("li").each( function() {
//			menu_height += $(this).height();
//		});

//		$("#flashcontent .menu_toggle").html( ((menu_toggle) ? "menu -" : "menu +") );
//		$("#header").css( {'height': 138 + menu_height});
//	});
//}

// div toggle //
function showonlyone(thechosenone) {
      var newboxes = document.getElementsByTagName("div");
            for(var x=0; x<newboxes.length; x++) {
                  name = newboxes[x].getAttribute("name");
                  if (name == 'newboxes') {
                        if (newboxes[x].id == thechosenone) {
                        newboxes[x].style.display = 'block';
                  }
                  else {
                        newboxes[x].style.display = 'none';
                  }
            }
      }
      if(is_mobile()) {
      	var scrto = $("#" + thechosenone).offset().top;
		$('html,body').animate({scrollTop: scrto},'slow');
      }
}


//equalizes div heights//
function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
					   

// email obsfucation //
function emailantispam(email1, email3, email4){
   emailE = email1 + '@' + email3 + email4;
   document.write('<a href="mailto:' + emailE + '">' + emailE + '</a>');
}

// Test for Mobile
// L3web 2011
function is_mobile() {
	if (navigator.userAgent.match(/android|webos|iphone|ipad|blackberry/i) != null) {
		return true;
	}
    return false;
}


