// Copyright (C) 2008 connor lowe



//Image pre-loader plug-in
jQuery.preloadImages = function() {
var a = (typeof arguments[0] == 'object')? arguments[0] : arguments;
for(var i = a.length -1; i > 0; i--) {
jQuery("<img>").attr("src", a[i]);
}
}

// Pre-load the images
$.preloadImages("images/mission.jpg", "images/gingerbread.jpg",
"images/contact.jpg", "images/content_img_blank.jpg");


//This is the code for the background swapping
var backImage = new Array();


backImage[0] = "/images/bg/1.jpg";
backImage[1] = "/images/bg/4.jpg";
backImage[2] = "/images/bg/2.jpg";
backImage[3] = "/images/bg/creativeroom-1.jpg";
backImage[4] = "/images/bg/creativeroom-2.jpg";
backImage[5] = "/images/bg/creativeroom-3.jpg";
backImage[6] = "/images/bg/creativeroom-4.jpg";
backImage[7] = "/images/bg/creativeroom-5.jpg";
backImage[8] = "/images/bg/3.jpg";
backImage[9] = "/images/bg/creativeroom-7.jpg";
backImage[10] = "/images/bg/creativeroom-9.jpg";
backImage[11] = "/images/bg/creativeroom-12.jpg";
backImage[12] = "/images/bg/creativeroom-13.jpg";
backImage[13] = "/images/bg/creativeroom-15.jpg";
backImage[14] = "/images/bg/creativeroom-18.jpg";
backImage[15] = "/images/bg/5.jpg";
backImage[16] = "/images/bg/6.jpg";
backImage[17] = "/images/bg/7.jpg";
backImage[18] = "/images/bg/creativeroom-19.jpg";
backImage[19] = "/images/bg/creativeroom-20.jpg";
backImage[20] = "/images/bg/creativeroom-21.jpg";
backImage[21] = "/images/bg/creativeroom-22.jpg";
backImage[22] = "/images/bg/creativeroom-23.jpg";
backImage[23] = "/images/bg/creativeroom-6.jpg";




// This is used in all of the functions that count. change this if you change the number of images in the array.
/*
	TODO - CHANGE THIS TO GET THE SIZE OF THE ARRAY
*/
var numImages = 24;

//counter holds a number for the background image array
var counter = Math.floor(Math.random()*numImages);	
//var counter = 17;	

//used in the function for collapsing the content module
var collapsed = true;

//used in the function for opening and closing the ticket drawer
var ticketDrawer_open = false;



	
	

	
	
	

	
	
	
$(function () {		
	
	
function firstLoad(){
	$('<div id="loading" class="active"></div>').html("loading...").appendTo('.columnHeader').fadeIn('slow');
	counter++;
	if (counter==numImages){
		counter=0;
	}
		var img = new Image();
		$(img)
			.hide()
			.load(function() {
				$('#loader').append(img);
				$('#loading').fadeOut('slow',function(){$(this).remove();});
				$(this).fadeIn(2000);
				})
			.attr({src: backImage[counter], id: "bg_image"})
			//.fadeIn(2000);
	
}
	
// This is called when the page first loads.
function ajaxifyLoad(file){
	//$('<div id="loadingStart"></div>').html("loading...").appendTo('.columnHeader').fadeIn();
	$.get(file,function(data) {
		$("#wrapper").html(data).fadeIn('slow');
	});
	toggleContent($('.columnHeader'));
}


// this is the function that will load the pages through ajax.	
function ajaxify(file){

	$('<div id="loading"></div>').html("loading...").appendTo('.columnHeader').fadeIn();
	$.get(file,function(data) {
		$("#wrapper").fadeOut('fast',function(){
			$(this).html(data).fadeIn('fast',function(){
				$('#loading').fadeOut('slow',function(){$(this).remove();});
			});
		});
	});
}




//function to toggle the content area
function toggleContent(element){
	if (collapsed == false) {
		$('#wrapper').toggle();
		$(element).css("-webkit-border-bottom-left-radius", "10px");
		$(element).css("-webkit-border-bottom-right-radius", "10px");
		$(element).css("-moz-border-radius-bottomleft", "10px");
		$(element).css("-moz-border-radius-bottomright", "10px");
	}
	else {
		$('#wrapper').toggle();
		$(element).css("-webkit-border-bottom-left-radius","");
		$(element).css("-webkit-border-bottom-right-radius","");
		$(element).css("-moz-border-radius-bottomleft", "");
		$(element).css("-moz-border-radius-bottomright", "");
	}
	collapsed = !collapsed;
}



	
		
$("ul.nav li a.ajax").click(function(){
		if($(this).hasClass('active')&&collapsed==true){
			toggleContent($('.columnHeader'));
		}

		else if(!$(this).hasClass('active')) {
		
			if(collapsed==true){
				$('.columnHeader').css("-webkit-border-bottom-left-radius","");
				$('.columnHeader').css("-webkit-border-bottom-right-radius","");
				$('.columnHeader').css("-moz-border-radius-bottomleft", "");
				$('.columnHeader').css("-moz-border-radius-bottomright", "");
				collapsed = !collapsed;
			}
		
			$('ul.nav li a.active').removeClass('active');
			$(this).addClass('active');
	
			ajaxify($(this).attr('href'));
		}
		return false;
	});						
		
	


		

$("#bg_button").click(function(){

	if(!$('#loading').hasClass('active') && !$('#loadingStart').hasClass('active')) {
		counter++;
		if (counter==numImages){
			counter=0;
		}
	
	
			if (collapsed == false) {
			$('<div id="loading" class="active"></div>').html("loading...").appendTo('.columnHeader').fadeIn(200);
			var img = new Image();
			$(img)
				.hide()
				.load(function(){
					$('#loader').append(this);
					$('#loading').fadeOut(1000,function(){$(this).remove();});							
					//$(this).fadeIn(2000);
					$("#bg_image:last").fadeOut(2000,function(){$(this).remove();});
				})
				.fadeIn(2000)
				.attr({src: backImage[counter], id: "bg_image"})
					
			}
		
	
			else {
			$('<div id="loadingStart" class="active"></div>').html("loading...").appendTo('.columnHeader').fadeIn();
			var img = new Image();
			$(img)
				.hide()
				.load(function(){
					$('#loader').append(this);
					$('#loadingStart').fadeOut(2000,function(){$(this).remove();});							
					//$(this).fadeIn(2000);
					$("#bg_image:last").fadeOut(2000,function(){$(this).remove();});
				})
				.fadeIn(2000)
				.attr({src: backImage[counter], id: "bg_image"})
			
		
		}
	}
	return false;
	
});
		
		

$("#ticket_button").click(function(){
	if(ticketDrawer_open==false){
		$(".drawer").slideDown();
		ticketDrawer_open=true;
	}
	else {
		$(".drawer").slideUp();
		ticketDrawer_open=false;
	}

	return false;

});


	
	

	

$(".columnHeader").click(function(){
	toggleContent(this);

	return false;
});




$(".bid_button").click(function(){
		$(".overlay").css("visibility", "visible")

		return false;
});
		
		
		
$(".no_entries").click(function(){
		$(".overlay").css("visibility", "visible")

		return false;
});
			
			
$(".close_overlay").click(function(){

		$(".overlay").css("visibility", "hidden")

		return false;
});




	firstLoad();
	ajaxifyLoad('about.php');

});



	

	




