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];}
}

(function($) {
		$.fn.slide = function(options) {
			var defaults = {
				slideWidth: 660,
				autoplay: true,
				duration: 8000,
				showNavigator: true,
				showSlideIndex: true
			};
			var options = $.extend(defaults, options);
			return this.each(function() {
				var slideshow = $(this);
				var o = options;
				var currentPosition = 0;
				var slides = $('.slide');
				var numberOfSlides = slides.length;
				var t;
	
				// Remove scrollbar in JS
				$('#slidesContainer').css('overflow', 'hidden');
	
				// Wrap all .slides with #slideInner div
				slides.wrapAll('<div id="slideInner"></div>')
	
				// Float left to display horizontally, readjust .slides width
				.css({
					'float': 'left',
					'width': o.slideWidth
				});
	
				// Insert a clone of first slide 
				$('.slide:first').clone().appendTo('#slideInner');
	
				// Set #slideInner width equal to total width of all slides
				$('#slideInner').css('width', o.slideWidth * (numberOfSlides + 1));
	
				// Insert controls in the DOM
				if (o.showNavigator) {
					slideshow
						.prepend('<span class="control" id="leftControl">Clicking moves left</span>')
						.append('<span class="control" id="rightControl">Clicking moves right</span>');
	
					// Create event listeners for .controls clicks
					$('#leftControl').click(function() { prev(); return false; });
					$('#rightControl').click(function() { next(); return false; });
				}
				// Insert slides index
				if (o.showSlideIndex == true) {
					slideshow.append('<div id="slideIndex"></div>');
					for (var i = 1; i <= numberOfSlides; i++) {
						$('#slideIndex').append('<span id="slide-' + i + '" class="numbers">' + i + '</span>');
					}
					$('.numbers').click(function() { goto(($(this).attr('id')).replace('slide-', '') - 1, false); return false; });
				}
	
				// Start
				init();
	
				//Init function
				function init() {
					manageControls(currentPosition);
					if (o.autoplay == true) setNextTimeOut(o.duration);
				}
	
				// Next
				function next() {
					currentPosition++;
					if (currentPosition >= numberOfSlides) currentPosition = 0;
					slideTo(currentPosition, true);
				}
	
				// Previous
				function prev() {
					currentPosition--;
					if (currentPosition < 0) currentPosition = numberOfSlides - 1;
					slideTo(currentPosition, false);
				}
	
				// Go to a slide 
				function goto(position) {
					currentPosition = position;
					slideTo(currentPosition, false);
				}
	
				// Set time out for next slide
				function setNextTimeOut() {
					t = setTimeout(function() { next(); }, o.duration);
				}
	
				function clearNextTimeOut()
				{ 
					clearTimeout(t);
				}
				// Slide
				function slideTo(position, continuously) {
					$('#slideInner').stop();
					clearNextTimeOut();
					// usual cases
					if (continuously == false || o.autoplay == false || position != 0) {
						$('#slideInner').animate({ 'marginLeft': o.slideWidth * (-position) }, '', '',
							function() {
								manageControls(position);
								if (o.autoplay == true) setNextTimeOut();
							}
						)
					}
					// autoplay: slide from last to first one continuously
					else {
						// slide to the 'fake' first slide (actually at the last)
						$('#slideInner').animate({ 'marginLeft': o.slideWidth * (-numberOfSlides) }, '', '',
							function() {
								//immediately change to the 'true' first slide
								$('#slideInner').css('marginLeft', 0);
								manageControls(position)
								if (o.autoplay == true) setNextTimeOut();
							}
						)
					}
				}
	
				// manageControls: Hides and Shows controls depending on currentPosition
				function manageControls(position) {
					if (o.showNavigator) {
						// Hide left arrow if position is first slide
						if (position == 0) { $('#leftControl').hide() } else { $('#leftControl').show() };
						// Hide right arrow if position is last slide
						if (position == (numberOfSlides - 1)) { $('#rightControl').hide() } else { $('#rightControl').show() };
					}
	
					// Hilight the current page
					if (o.showSlideIndex == true) {
						// remove active class from all pages
						$('.numbers').removeClass("active");
						// add only to the current page
						$('#slide-' + (position + 1)).addClass("active");
					}
				}
			});
		};
	})(jQuery);
$(document).ready(function() {	
	 $('#slideshow').slide({autoplay: true, duration: 5000, showSlideIndex: true});
	// Notice the use of the each() method to acquire access to each elements attributes
   $('.menuItem a[tooltip]').each(function()
   {
      $(this).qtip({
         content: $(this).attr('tooltip'),// Use the tooltip attribute of the element for the content
		   position: {
			  corner: {
				 target: 'middleLeft',
				 tooltip: 'middleLeft'
			  },
			  adjust:{
				  x:-304,
				  y:-95
			  }
		   },
         style: { 
		 	width: 300,
			  padding: 5,
			  background: '#282D33',
			  color: '#ffffff',
			  textAlign: 'left',
			  "font-size": 12,
			  "line-height":1.1,
			  "height":75,
			  border: {
				 width: 2,
				 radius: 5,
				 color: '#FA1D7A'
      			},
			  tip: {
				corner:'rightBottom',// Notice the corner value is identical to the previously mentioned positioning corners 
				size:{
					x:10,
					y:10
				}
			  }
			}
      });
   });

	$(".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
		//}
	//);
});
