// JavaScript Document

currentRef = "";

function findLargest(arr){
	var largest = arr[0];
	for(var i=1;i<=arr.length;i++){
		if(arr[i] > largest){
			largest = arr[i];
		}
	}
	return largest;
}

function testGal(){
	$(".testimony:first-child").clone().appendTo("#testSlider");
	numTest = $(".testimony").length;
	testI = 1;
	testW = 550;
	tmpX = 0;
	numSec = 5;
	pauseDur = 6000;
	twDur = 1875;
	easing = "easeOutQuad";
	timer = setTimeout("testIter()",pauseDur);
}

function testIter(){
	//alert("contact");
	if(testI >= numTest){
		tmpX = -550;
		$("#testSlider").css("left","0px");
		testI = 1;
	} else {
		tmpX = tmpX-testW;
	}
	newX = tmpX+"px";
	$("#testSlider").animate({"left":newX},twDur,easing);
	testI++;
	timer = setTimeout("testIter()",pauseDur);
}

function adjCols(){
	$("#subNav").css("height","auto");
	$("#plainContent").css("height","auto");
	$("#pageContent").css("height","auto");
	var lenArr = new Array(500,$("#subNav").height(),$("#pageContent").height(),$("#plainContent").height(),$("#heroFlash").height());
	var lg = findLargest(lenArr)+"px";
	lg = "510px";
	$("#subNav").css("height",lg);
	$("#pageContent").css("height",lg);
	$("#plainContent").css("height",lg);
	$("#content").css("height","auto");
}

function adjNav(){
	//alert("test");
	$("#nav ul").css("width","auto");
	var navW = $("#nav ul").width();
	var blogW = $("#nav li.blog").width();
	//alert(navW);
	var newW = blogW + (957-navW+2);
	$("#nav li.blog").width(newW);
}

$("#nav").ready(function(){
	//adjNav();
});

$(".testimony").ready(function(){
	h = $("#testimonials").height();
	$(".testimony").each(function(){
		tmpH = $(this).height();
		newY = (h - tmpH)*.2;
		newY = newY+"px";
	});
	testGal();
});

function loadSection(pageId,sectionName){
	$("#nav li").each(function(){
		if($(this).hasClass('selected')){
			$(this).removeClass('selected');
		}
	});
	//$("#content").css("height",$("#content").height());
	//alert(sectionName);
	$("#content").empty();
	$("#content").load('http://www.cochon555.com/blog/?page_id='+pageId);
}

$("#nav li").ready(function(){
	$("#nav li").mousedown(function(){
		btnClass = $(this).attr('class');
		//alert(btnClass);
		wide = 800;
		switch(btnClass){
			case "tourDates" : pageId = 4; break;
			case "sponsors" : pageId = 9; break;
			case "tickets" : pageId = 11; wide = 1000; break;
			case "media" : pageId = 17; break;
			case "about" : pageId = 2; break;
			case "contact" : pageId = 13; break;
			case "blog" : pageId = false; btnUrl = 'http://cochon555ustour.blogspot.com'; break;
		}
		
		//alert(pageId);
		if(!pageId){
			//window.open(btnUrl);
			window.open(btnUrl,"CochonPop","width="+wide+",height=600,menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes");
		} else {
			$("#nav li").each(function(){
				if($(this).hasClass('selected')){
					$(this).removeClass('selected');
				}
			});
			var searchStr = "#nav li."+btnClass;
			//alert(searchStr);
			if(!isIE6){
				$(searchStr).addClass('selected');
			}
			$("#content").css("height",$("#content").height());
			$("#content").empty();
			//$("#content").load('http://www.cochon555.com/blog/?page_id='+pageId);
			
			var loadUrl = 'http://www.cochon555.com/blog/?page_id='+pageId;
			$.ajax(
				{
					method: "get",
					url: loadUrl,
					timeout: (5000),	 
					 
					 // Define the succss method.
					 success: function(data){
						//alert(data);
						$("#content").html(data);
					 },
					 // Define the error method.
					 error: function( objAJAXRequest, strError ){
					 //alert("error");
						 window.location.replace("home.php?id="+pageId+"&type=section&class="+btnClass)
					 }
				}
			 );
			
		}
	});
	$("#content").ajaxSuccess(function(){//alert("success");
									   });
	$("#content").ajaxComplete(function(){//alert("complete");
									   });
	$("#content").ajaxError(function(){//alert("error");
									   });
	$("#content").ajaxStart(function(){//alert("start");
									   });
});

function loadPage(pageId){
	$("#accordion li a").each(function(){
		if($(this).hasClass('selected')){
			$(this).removeClass('selected');
		}
	});
	$("#content").css("height",$("#content").height());
	$("#pageContent").empty();
	//$("#pageContent").load('http://www.cochon555.com/blog/?page_id='+pageId);
			
			var loadUrl = 'http://www.cochon555.com/blog/?page_id='+pageId;
			$.ajax(
				{
					method: "get",
					url: loadUrl,
					timeout: (5000),	 
					 
					 // Define the succss method.
					 success: function(data){
						//alert(data);
						$("#pageContent").html(data);
					 },
					 // Define the error method.
					 error: function( objAJAXRequest, strError ){
						 window.location.replace("home.php?id="+pageId+"&type=page")
					 }
				}
			 );
}

$("#pageContent, #plainContent, #heroFlash").ready(function(){
	adjCols();
});

$(document).ready(function(){
	//adjCols();
});

$("#accordion").ready(function(){
	$("#accordion").accordion({ active:'none',autoHeight: false, clearStyle: true , collapsible: true});
});

function openGallery(){
	$("#galleryPop").dialog('open');
}

$("#galleryPop").ready(function(){
$("#galleryPop").dialog({
	bgiframe: false,
	autoOpen: false,
	height: 575,
	width: 780,
	resizable: false,
	modal: true});
	swfobject.embedSWF("flash/gallery.swf", "galleryFlash", "750", "500", "9.0.0");
});

$("#faqPop").ready(function(){
$("#faqPop").dialog({
	bgiframe: false,
	autoOpen: false,
	height: 450,
	width: 450,
	resizable: false,
	modal: true});
	$("#faqPop .popContent").load('http://www.cochon555.com/blog/?page_id=410');
});

$("#privacyPop").ready(function(){
$("#privacyPop").dialog({
	bgiframe: false,
	autoOpen: false,
	height: 500,
	width: 480,
	resizable: false,
	modal: true});
	$("#privacyPop .popContent").load('http://www.cochon555.com/blog/?page_id=412');
});

function openFaq(){
	$("#faqPop").dialog('open');
}

function openPrivacy(){
	$("#privacyPop").dialog('open');
}


function clickclear(thisfield) {
	thisfield.value = "";
}

$("#newsRoomPop").ready(function(){
$("#newsRoomPop").dialog({
	bgiframe: false,
	autoOpen: false,
	height: 450,
	width: 450,
	resizable: false,
	modal: true});
	$("#newsRoomPop .popContent").load('http://www.cochon555.com/blog/?page_id=533');
});

function openNewsroom(){
	$("#newsRoomPop").dialog('open');
}

$("#newsLetterPop").ready(function(){
$("#newsLetterPop").dialog({
	bgiframe: false,
	autoOpen: false,
	height: 450,
	width: 450,
	resizable: false,
	modal: true});
	$("#newsLetterPop .popContent").load('http://www.cochon555.com/blog/?page_id=696');
});

function openNewsletter(){
	$("#newsLetterPop").dialog('open');
}

function maxWindow()
{
	window.moveTo(0,0);
	
	
	if (document.all)
	{
	  top.window.resizeTo(screen.availWidth,screen.availHeight);
	}
	
	else if (document.layers||document.getElementById)
	{
	  if (top.window.outerHeight<screen.availHeight||top.window.outerWidth<screen.availWidth)
	  {
		top.window.outerHeight = screen.availHeight;
		top.window.outerWidth = screen.availWidth;
	  }
	}
}
