function redirectTo(obj) {
	if (obj[obj.selectedIndex].value.indexOf("http") > -1) {
		window.open(obj[obj.selectedIndex].value);
	}
	else {
		window.location = obj[obj.selectedIndex].value;
	}
}

function reveal(id) {
	if ($("#" + id)	.css("display") == "none") {
		$("#" + id).slideDown("normal");	
		$("." + id).text("Close");
	}
	else {
		$("#" + id).slideUp("normal");	
		$("." + id).text("Learn More");
	}
}

function updateCallout(newTxt) {
	$("#menuCallout").html(newTxt);	
}

function homeShare() {
	window.open("/summer/email.php?url=http://www.berklee.edu/summer", "email", 	"width=500,height=500,menubar=no,status=no,resizable=no,titlebar=no,toolbar=no,scrollbars=no");
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

$(document).ready(function() {
	$(".delicious").click(function() {
		window.open('http://del.icio.us/post?url=' + window.location.href + '&title=' + document.title);
		return false;
	});
	
	$(".digg").click(function() {
		window.open('http://digg.com/submit?phase=2&url=' + window.location.href);
		return false;
	});
	
	$(".facebook").click(function() {
		var u = window.location.href;
		var t = document.title;
		window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + 
		encodeURIComponent(t), 'sharer', 'toolbar=0, status=0, width=626, height=436');
		return false;
	});
	
	$(".myspace").click(function() {
		var targetUrl = 'http://www.myspace.com/Modules/PostTo/Pages/?' + 't=' +
		encodeURIComponent(document.title) + '&c=' + encodeURIComponent($("#content").text().slice(0, 200) + "...") + '&u=' + 
		encodeURIComponent(window.location.href) + '&l=' + 2;
		window.open(targetUrl);
		return false;
	});
	
	$(".reddit").click(function() {
		window.open('http://reddit.com/submit?url=' + window.location.href + '&title=' + document.title);
		return false;
	});
	
	$(".stumbleupon").click(function() {
		window.open('http://www.stumbleupon.com/submit?url=' + window.location.href);
		return false;
	});
	
	$(".email").click(function() {
		var currentURL = window.location.href;
		var w = window.open("/summer/email.php?url=" + currentURL, "email", "width=500,height=500,menubar=no,status=no,resizable=no,titlebar=no,toolbar=no,scrollbars=no");
		return false;
	});
	
	$(".print").click(function() {
		window.print();						   
	});
	
	$(".applyNowImage").toggle(
		 function() {
			 $("#applyNow").show();
			 $(this).attr("src", "/summer/resources/images/navSecondary_applynow_down.gif");
		 },
		 function() {
			 $("#applyNow").hide();
			 $(this).attr("src", "/summer/resources/images/navSecondary_applynow_up.gif");
		 }
	);
	
	MM_preloadImages('/summer/resources/images/navMain_bassline_down.gif','/summer/resources/images/navMain_losangeles_down.gif','/summer/resources/images/navMain_dublin_up.gif','/summer/resources/images/navMain_percussionfestival_down.gif','/summer/resources/images/navMain_brassweekend_down.gif','/summer/resources/images/navMain_businessofmusic_down.gif','/summer/resources/images/navMain_fiveweeksummer_down.gif','/summer/resources/images/navMain_guitarsessions_down.gif','/summer/resources/images/navMain_imeli_down.gif','/summer/resources/images/navMain_videogames_down.gif','/summer/resources/images/navMain_productionworkshop_down.gif','/summer/resources/images/navMain_musictherapy_down.gif','/summer/resources/images/navMain_summerpiano_down.gif','/summer/resources/images/navMain_saxophoneweekend_down.gif','/summer/resources/images/navMain_songwriting_down.gif','/summer/resources/images/navMain_stageperformance_down.gif','/summer/resources/images/navMain_acousticstringfestival_down.gif','/summer/resources/images/navMain_twelveweekfullcredit_down.gif','/summer/resources/images/navMain_vocalsummit_down.gif');
	
	MM_preloadImages('/summer/resources/images/navSecondary_applicationcalendar_down.gif', '/summer/resources/images/navSecondary_requestinfo_down.gif', '/summer/resources/images/navSecondary_videos_down.gif','/summer/resources/images/navSecondary_applynow_down.gif','/summer/resources/images/navSecondary_contactus_down.gif','/summer/resources/images/navSecondary_berkleeedu_down.gif');
	
	$("#menu").find("img").hover(
		function() {
			for (var i = 0; i < json_sections.sections.section.length; i++) {
				if (json_sections.sections.section[i]["@attributes"].id == $(this).attr('id')) {
					updateCallout(json_sections.sections.section[i].copy);
				}
			}
		},
		function() {
			//don't want to turn stuff off
		}
	);
});