window.onload = function() {
    setMainImageSize();
    $(function() {
		// Set drag scroll on first descendant of class dragger on both selected elements
		$('#container').dragscrollable({dragSelector:'.dragMe, .song p', acceptPropagatedEvent: false});
		
		var myWidth = document.getElementById('container').offsetWidth;
		var myHeight = document.getElementById('container').offsetHeight;
		
		$('div.pane').scrollTo( 0 );
		// Reset the screen to (0,0)
		$.scrollTo( 0 );
		
		var left = 1056 - (((myWidth-0) - 722) /2);
		var top = 1260 - (((myHeight-0) - 172) /2); 
		
		$('#container').scrollTop(top);
		$('#container').scrollLeft(left);
		
		$('#container').scroll(function() {
			var container = document.getElementById('container');
			var scrollTop = container.scrollTop;
			var scrollLeft = container.scrollLeft;
			var myWidth = container.offsetWidth;
			var myHeight = container.offsetHeight;
			var left = 1056 - (((myWidth-0) - 722) /2);
			var top = 1260 - (((myHeight-0) - 172) /2); 
			
			if((container.getAttribute('class') == 'full') || (container.getAttribute('className') == 'full')) {
				
			} else {
				//$('#container').addClass('full'); setMainImageSize();
			}
			
			//tracklisting
		 	if(((scrollLeft > 1100) && (scrollLeft < 1700)) && ((scrollTop > 800) && (scrollTop < 1500))) {
		 		document.getElementById('tracklisting').setAttribute('class', 'show');
		 	} else {
		 		document.getElementById('tracklisting').setAttribute('class', '');
		 	}
		 	
		 	//horchata
		 	if(((scrollLeft >= 0) && (scrollLeft < 400)) && ((scrollTop >= 0) && (scrollTop < 800))) {
		 		document.getElementById('horchata').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('horchata').setAttribute('class', 'song');
		 	}
		 	
		 	//white sky
		 	if(((scrollLeft > 1300) && (scrollLeft < 1900)) && ((scrollTop > 1700) && (scrollTop < 2500))) {
		 		document.getElementById('whitesky').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('whitesky').setAttribute('class', 'song');
		 	}
		 	
		 	//holiday
		 	if(((scrollLeft > 1100) && (scrollLeft < 1700)) && ((scrollTop >= 0) && (scrollTop < 900))) {
		 		document.getElementById('holiday').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('holiday').setAttribute('class', 'song');
		 	}
		 	
		 	//californiaenglish
		 	if(((scrollLeft >= 0) && (scrollLeft < 400)) && ((scrollTop > 1100) && (scrollTop < 2200))) {
		 		document.getElementById('californiaenglish').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('californiaenglish').setAttribute('class', 'song');
		 	}
		 	
		 	//taxicab
		 	if(((scrollLeft > 1700) && (scrollLeft < 3500)) && ((scrollTop > 1800) && (scrollTop < 3000))) {
		 		document.getElementById('taxicab').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('taxicab').setAttribute('class', 'song');
		 	}
		 	
		 	//run
		 	if(((scrollLeft > 1700) && (scrollLeft < 3500)) && ((scrollTop >= 0) && (scrollTop < 900))) {
		 		document.getElementById('run').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('run').setAttribute('class', 'song');
		 	}
		 	
		 	//cousins
		 	if(((scrollLeft > 400) && (scrollLeft < 1100)) && ((scrollTop >= 0) && (scrollTop < 700))) {
		 		document.getElementById('cousins').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('cousins').setAttribute('class', 'song');
		 	}
		 	
		 	//givingupthegun
		 	if(((scrollLeft > 300) && (scrollLeft < 1100)) && ((scrollTop > 2000) && (scrollTop < 3000))) {
		 		document.getElementById('givingupthegun').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('givingupthegun').setAttribute('class', 'song');
		 	}
		 	
		 	//diplomatsson
		 	if(((scrollLeft > 900) && (scrollLeft < 1700)) && ((scrollTop > 1700) && (scrollTop < 3000))) {
		 		document.getElementById('diplomatsson').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('diplomatsson').setAttribute('class', 'song');
		 	}
		 	
		 	//ithinkuracontra
		 	if(((scrollLeft >= 0) && (scrollLeft < 500)) && ((scrollTop > 2200) && (scrollTop < 3000))) {
		 		document.getElementById('ithinkuracontra').setAttribute('class', 'song show');
		 	} else {
		 		document.getElementById('ithinkuracontra').setAttribute('class', 'song');
		 	}
		});
		
	});
}

window.onresize = function() {
    setMainImageSize();
}

var type = "";
if (navigator.userAgent.indexOf("Opera")!=-1 && document.getElementById) type="OP";
if (document.all) type="IE";
if (document.layers) type="NN";
if (!document.all && document.getElementById) type="MO";

function setMainImageSize() {
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
			//Non-IE
		 myWidth = window.innerWidth;
		 myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
			//IE 4 compatible
			myWidth = document.body.clientWidth;
			myHeight = document.body.clientHeight;
	}
	
	var container = document.getElementById('container');
	
	var heightOffset = 0;
	
	if((container.getAttribute('class') == 'full') || (container.getAttribute('className') == 'full')) {
		heightOffset = 0;
	}
	
	container.style.height = (myHeight-50-heightOffset) + "px";
    
    var feature = document.getElementById('feature');
    feature.style.height = (myHeight-50-heightOffset) + "px";
    
    var myHeight = document.getElementById('container').offsetHeight;
    var top = 1260 - (((myHeight-0) - 172) /2); 
    
    var moretop = top + myHeight - 68 - 25;
	document.getElementById('logotext').style.top = moretop + 'px';
 	
 	var holiday_image = document.getElementById('holiday_cs_img');
 	
 	if(holiday_image != null) {
 		
 		var new_width = myWidth;
 		var new_height = (myWidth/2500) * 1710;
 		if(new_height > myHeight) {
 			
 			holiday_image.style.height = new_height + 'px';
 			holiday_image.style.width = new_width + 'px';
 			
 			var top_margin = (myHeight - new_height)/2;
 			holiday_image.style.top = top_margin + 'px';
 			
 		} else {
 			
 			var new_height = myHeight;
			var new_width = (myHeight/1710) * 2500;
 			
 			holiday_image.style.height = new_height + 'px';
 			holiday_image.style.width = new_width + 'px';
 			
 			var left_margin = (myWidth - new_width)/2;
 			holiday_image.style.left = left_margin + 'px';
 			
 		}
 		
 		var holidayvideoframe = document.getElementById('holidayvideoframe');
 		
 		holidayvideoframe.style.height = (myHeight - 100) + 'px';
 		holidayvideoframe.style.width = (myWidth - 100) + 'px';
 		
 	}
 	
 	/*
 	
 	var fall_tour = document.getElementById('fall_tour');
 	
 	if(fall_tour != null) {
 		
 		var new_width = myWidth;
 		var new_height = (myWidth/2500) * 1710;
 		if(new_height > myHeight) {
 			
 			fall_tour.style.height = new_height + 'px';
 			fall_tour.style.width = new_width + 'px';
 			
 			var top_margin = (myHeight - new_height)/2;
 			fall_tour.style.top = top_margin + 'px';
 			
 		} else {
 			
 			var new_height = myHeight;
			var new_width = (myHeight/1710) * 2500;
 			
 			fall_tour.style.height = new_height + 'px';
 			fall_tour.style.width = new_width + 'px';
 			
 			var left_margin = (myWidth - new_width)/2;
 			fall_tour.style.left = left_margin + 'px';
 			
 		}
 		
 	}
 	   */
}

function fieldFocus(element, text)
{
	if(text == element.value) {
		element.value = "";
	}
}
function fieldBlur(element, text)
{
	if("" == element.value) {
		element.value = text;
	}
}


function checkForm()
{
    emailaddress = document.getElementById('email_input');
    if("your@email.com" == emailaddress.value) {
        alert("Please enter a valid email address");
        return false;
    } else {
        document.subscribeform.submit();
    }
}


function toggleBuy() {
	var buylinks = document.getElementById('buylinks');
	
	if((buylinks.getAttribute('class') == 'show') || (buylinks.getAttribute('className') == 'show')) {
		buylinks.setAttribute('class', '');
		buylinks.setAttribute('className', '');
	} else {
		buylinks.setAttribute('class', 'show');
		buylinks.setAttribute('className', 'show');
	}
}

var feature_count = 0;
var feature_max = 3;

function nextFeature() {
	
	var feature = document.getElementById('feature');
	
	feature_count = feature_count + 1;
	
	if(feature_count > feature_max) {
		feature_count = 0;
	}
	
	if(feature_count == 1) {
		feature.setAttribute('class', 'active2');
	} else if(feature_count == 2) {
		feature.setAttribute('class', 'active3');
	} else if(feature_count == 3) {
		feature.setAttribute('class', 'active4');
	} else if(feature_count == 4) {
		feature.setAttribute('class', 'active5');
	} else {
		feature.setAttribute('class', '');
	}
	
}

function prevFeature() {
	
	var feature = document.getElementById('feature');
	
	feature_count = feature_count - 1;
	
	if(feature_count < 0) {
		feature_count = feature_max;
	}
	
	if(feature_count == 1) {
		feature.setAttribute('class', 'active2');
	} else if(feature_count == 2) {
		feature.setAttribute('class', 'active3');
	} else if(feature_count == 3) {
		feature.setAttribute('class', 'active4');
	} else if(feature_count == 4) {
		feature.setAttribute('class', 'active5');
	} else {
		feature.setAttribute('class', '');
	}
	
}

