function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = jQuery(this).outerHeight(true);
		if(thisHeight > tallest) {
			tallest = thisHeight-5;
		}
	});
	group.height(tallest);
}
jQuery(document).ready(function() {
	setTimeout(function(){
		equalHeight(jQuery(".matchheight"));
	}, 300);
});


// @@ START Media Box 

jQuery(function() { 
  	jQuery(".media-carousel-content").scrollable({ 
	
	circular: false, 
	mousewheel: true,
	onSeek: function() {
		switch (this.getIndex()) {
		case 0:
		jQuery('#media-module-bg').css("background-color","#eb8c00");
		break;
		
		case 1:
		jQuery("#media-module-bg").css("background-color","#dc6900");
		break;
		
		case 2:
		jQuery("#media-module-bg").css("background-color","#e0301e");
		break;
		
		case 3:
		jQuery("#media-module-bg").css("background-color","#db536a");
		break;
		
		case 4:
		jQuery("#media-module-bg").css("background-color","#a32020");
		break;
		
		case 5:
		jQuery("#media-module-bg").css("background-color","#602320");
		break;

	}
	}
	}).navigator({

	// select #flowtabs to be used as navigator
	navi: "#media-slideshow-tabs",

	// select A tags inside the navigator to work as items (not direct children)
	naviItem: 'a',

	// assign "current" class name for the active A tag inside navigator
	activeClass: 'current',

	// make browser's back button work
	history: true

});
jQuery("#media-slideshow-tabs").fadeIn();

});

// @@ END Media Box 

// @@ START Homepage feature 2

// Apple detection object
function checkForApple(){
	var Apple = {};  
	Apple.UA = navigator.userAgent;  
	Apple.Device = false;  
	Apple.Types = ["iPhone", "iPod", "iPad"];  
	for (var d = 0; d < Apple.Types.length; d++) {  
		var t = Apple.Types[d];  
		Apple[t] = !!Apple.UA.match(new RegExp(t, "i"));  
		Apple.Device = Apple.Device || Apple[t];  
	}  
	// is this an Apple device?  
	/*alert(  
		"Apple device? " + Apple.Device +  
		"\niPhone? " + Apple.iPhone +  
		"\niPod? " + Apple.iPod +  
		"\niPad? " + Apple.iPad  
	); */
	if(Apple.iPhone==true || Apple.iPad==true || Apple.iPod==true){
		return true;
	} else {
		return false;
	}
}

jQuery(document).ready(function(){
	setTimeout(init,1500);
});
function init(){
	startAnimation();
}
function startAnimation(){
	setTimeout(startRose,500);
	setTimeout(startTang,1000);
	setTimeout(startYellow,1250);
	setTimeout(startOrange,1500);
	setTimeout(startRed,1750);
	setTimeout(revealText,3000);
}
// animation first stage
function nextYellow(){
	jQuery('#yellow').animate({width:"680px",height:"288px"},1000);
}
function nextTang(){
	jQuery('#tangerine').animate({width:"505px",height:"406px"},750);
}
function nextOrange(){
	jQuery('#orange').animate({width:"608px",height:"288px"},500);
}
function nextRed(){
	jQuery('#red').animate({width:"151px",height:"384px"},800);
}
function nextRose(){
	jQuery('#rose').animate({width:"820px",height:"122px"},1400);
}
// animation second stage
function startYellow(){
	jQuery('#yellow').animate({width:"668px",height:"385px"},1000,nextYellow());
}
function startTang(){
	jQuery('#tangerine').animate({width:"748px",height:"288px"},750,nextTang());
}
function startOrange(){
	jQuery('#orange').animate({width:"442px"},500,nextOrange());
}
function startRed(){
	jQuery('#red').animate({width:"638px"},800,nextRed());
}
function startRose(){
	jQuery('#rose').animate({width:"778px"},1400,nextRose());
}
function revealText(){
	/*alert('text box triggered');*/
	jQuery('#textbox').fadeIn(1000);
}

// @@ END Homepage feature 2

function writesharelinkHome() {
	document.write("<li id='ptshare'><a href='#' target='_self' class='shareicon' onclick='shareboxrevealHome(); return false;'>" + sharetitle + "</a></li>");
}
	
function shareboxrevealHome() { // Show, hide or add to territory selector box
	if(document.getElementById('sharebox').style.display=='none') {
		var col = document.getElementById('home-boxes').offsetHeight;
		document.getElementById('sharebox').style.display = 'block';
		var share = document.getElementById('sharebox').offsetHeight;
		document.getElementById('home-boxes').style.height = col + share + 'px';
	}
}

function shareboxhideHome() { 	// Clear the contents of the box and hide the div
	var col = document.getElementById('home-boxes').offsetHeight;
	var share = document.getElementById('sharebox').offsetHeight;
	document.getElementById('home-boxes').style.height = col - share + 'px';
	document.getElementById('sharebox').style.display = 'none';
}

function writeshareboxHome() { // Taken from HTML for 3rd party templates
	if (arr_ss [0] === undefined) {
		// Twitter
		arr_ss [0] = new Array()
		arr_ss [0][0] = "/assets/image/share_twitter.gif";
		arr_ss [0][1] = "http://twitter.com/home?status=" + escape(window.location);
		arr_ss [0][2] = "";  // E.G. arr_ss [0][2] = "&param=something";
		arr_ss [0][3] = "Twitter";
		arr_ss [0][4] = "";
	}

	if (arr_ss [1] === undefined) {
		// Facebook
		arr_ss [1] = new Array()
		arr_ss [1][0] = "/assets/image/share_facebook.gif";
		arr_ss [1][1] = "http://www.facebook.com/share.php?u=" + escape(window.location);
		arr_ss [1][2] = "";
		arr_ss [1][3] = "Facebook";
		arr_ss [1][4] = "";
	}
	
	if (arr_ss [2] === undefined) {
		// Linkedin
		arr_ss [2] = new Array()
		arr_ss [2][0] = "/assets/image/share_linked.gif";
		arr_ss [2][1] = "http://www.linkedin.com/shareArticle?mini=true&url=" + escape(window.location);
		arr_ss [2][2] = "";
		arr_ss [2][3] = "Linkedin";
		arr_ss [2][4] = "";
	}
	
	if (arr_ss [3] === undefined) {
		// Mixx
		arr_ss [3] = new Array()
		arr_ss [3][0] = "/assets/image/share_mixx.gif";
		arr_ss [3][1] = "http://www.mixx.com/submit?page_url=" + escape(window.location);
		arr_ss [3][2] = "";
		arr_ss [3][3] = "Mixx";
		arr_ss [3][4] = "";
	}

	if (arr_ss [4] === undefined) {
		// Digg
		arr_ss [4] = new Array()
		arr_ss [4][0] = "/assets/image/share_digg.gif";
		arr_ss [4][1] = "http://digg.com/submit?phase=2&url=" + escape(window.location);
		arr_ss [4][2] = "";
		arr_ss [4][3] = "Digg";
		arr_ss [4][4] = "";
	}

	if (arr_ss [5] === undefined) {
		// Google buzz
		arr_ss [5] = new Array()
		arr_ss [5][0] = "/assets/image/share_googlebuzz.gif";
		arr_ss [5][1] = "http://www.google.com/reader/link?url=" + escape(window.location);
		arr_ss [5][2] = "";
		arr_ss [5][3] = "Google buzz";
		arr_ss [5][4] = "";
	}

	var sendshare = "<div id='sharebox' style='display: none;'><ul id='shareicons'><div id='shareboxclose'><a href='#' onClick='shareboxhideHome(); return false;'><img src='/assets/image/icon_close.gif' alt='Close' border='0' /></a></div>"	
	if (window.sendsharetitle === undefined) { window.sendsharetitle = escape("Page title here"); }
	for (i=0;i<arr_ss.length; i++) {
	    sendshare = sendshare + "<li id='share" + i + "'><a href='" + arr_ss[i][1] + "&title=" + sendsharetitle + arr_ss[i][2] + "' onclick='" + arr_ss[i][4] + "' target='_blank' class='shareicon'><img src='" + arr_ss[i][0] + "' border='0' alt='" + arr_ss[i][3] + "' />&nbsp;" + arr_ss[i][3] + "</a></li>";	
	}
	sendshare = sendshare + "</ul></div>";
	document.write(sendshare);
}
