// 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");


//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";




// This is used in all of the functions that count. change this if you change the number of images in the array.
var numImages = 18;


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

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

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

var patkauDrawer_open = false;
var lumDrawer_open = false;
var ritchieDrawer_open = false;
var jonesDrawer_open = false;
var pechetDrawer_open = false;
	
	

	
	
	

	
	
	
$(function () {		
	
	
	function firstLoad(){
		$(".drawer").hide();
		$('<div id="loading" class="active"></div>').html("loading...").appendTo('.columnHeader').fadeIn('slow');
		counter++;
		if (counter==numImages){
			counter=0;
		}
		$(function() {
			var img = new Image();
			$(img).load(function() {
				$('#loader').append(img);
				$('#loading').fadeOut('slow',function(){$(this).remove();});
			}).attr({src: backImage[counter], id: "bg_image"});
			$(img).fadeIn('slow');
		
		});
		
		
	}
	
	
	
	// 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();});
					});
				});
			});
		}



		// This is called when the page first loads.
		function ajaxifyLoad(file){
			//$('<div id="loadingStart"></div>').html("loading...").appendTo('.columnHeader').fadeIn();
			$('.columnHeader').css("-webkit-border-bottom-left-radius","10px");
			$('.columnHeader').css("-webkit-border-bottom-right-radius","10px");
			$('.columnHeader').css("-moz-border-radius-bottomleft", "10px");
			$('.columnHeader').css("-moz-border-radius-bottomright", "10px");
			collapsed = !collapsed;
			$.get(file,function(data) {
				$("#wrapper").fadeOut('fast',function(){
					$(this).html(data).fadeOut('fast',function(){
						//$('#loadingStart').fadeOut('slow',function(){$(this).remove();});
					});
				});
			});
		}
	
	
		
/*	$("ul.nav li a").click(function(){
			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;
			}
				
			$('.nav ul li a.active').removeClass('active');
			$(this).addClass('active');
		
			ajaxify($(this).attr('href'));

			return false;
		});						
		
				
	*/
	
	
		$("#ticket_button").click(function(){
			if(ticketDrawer_open==false){
				$("#ticket_drawer").slideDown();
				ticketDrawer_open=true;
			}
			else {
				$("#ticket_drawer").slideUp();
				ticketDrawer_open=false;
			}
			
			return false;
			
		});
		
		
		
		
		$("#patkau_toggle").click(function(){
			if(patkauDrawer_open==false){
				if(lumDrawer_open==true){
					$("#lum_drawer").css('z-index', '');
					$("#lum_drawer").slideUp();
					lumDrawer_open=false;
				}
				else if(ritchieDrawer_open==true){
					$("#ritchie_drawer").css('z-index', '');
					$("#ritchie_drawer").slideUp();
					ritchieDrawer_open=false;
				}
				
				$("#patkau_drawer").css('z-index', '1000');
				$("#patkau_drawer").slideDown();
				patkauDrawer_open=true;
			}
			else {
				$("#patkau_drawer").slideUp().css('z-index', '');
				patkauDrawer_open=false;
			}
			
			return false;
			
		});
		
		$("#jones_toggle").click(function(){
			if(jonesDrawer_open==false){
				if(lumDrawer_open==true){
					$("#lum_drawer").css('z-index', '');
					$("#lum_drawer").slideUp();
					lumDrawer_open=false;
				}
				else if(ritchieDrawer_open==true){
					$("#ritchie_drawer").css('z-index', '');
					$("#ritchie_drawer").slideUp();
					ritchieDrawer_open=false;
				}
				else if(pechetDrawer_open==true){
					$("#pechet_drawer").css('z-index', '');
					$("#pechet_drawer").slideUp();
					pechetDrawer_open=false;
				}
				
				$("#jones_drawer").css('z-index', '1000');
				$("#jones_drawer").slideDown();
				jonesDrawer_open=true;
			}
			else {
				$("#jones_drawer").slideUp().css('z-index', '');
				jonesDrawer_open=false;
			}
			
			return false;
			
		});
		
		$("#lum_toggle").click(function(){
			if(lumDrawer_open==false){
				if(jonesDrawer_open==true){
					$("#jones_drawer").css('z-index', '');
					$("#jones_drawer").slideUp();
					patkauDrawer_open=false;
				}
				else if(ritchieDrawer_open==true){
					$("#ritchie_drawer").css('z-index', '');
					$("#ritchie_drawer").slideUp();
					ritchieDrawer_open=false;
				}
				else if(pechetDrawer_open==true){
					$("#pechet_drawer").css('z-index', '');
					$("#pechet_drawer").slideUp();
					pechetDrawer_open=false;
				}
				
				$("#lum_drawer").css('z-index', '1000');
				$("#lum_drawer").slideDown();
				lumDrawer_open=true;
			}
			else {
				$("#lum_drawer").css('z-index', '');
				$("#lum_drawer").slideUp();
				lumDrawer_open=false;
			}
			
			return false;
			
		});
		
		$("#pechet_toggle").click(function(){
			if(pechetDrawer_open==false){
				if(lumDrawer_open==true){
					$("#lum_drawer").css('z-index', '');
					$("#lum_drawer").slideUp();
					lumDrawer_open=false;
				}
				else if(ritchieDrawer_open==true){
					$("#ritchie_drawer").css('z-index', '');
					$("#ritchie_drawer").slideUp();
					ritchieDrawer_open=false;
				}
				else if(jonesDrawer_open==true){
					$("#jones_drawer").css('z-index', '');
					$("#jones_drawer").slideUp();
					pechetDrawer_open=false;
				}
				
				$("#pechet_drawer").css('z-index', '1000');
				$("#pechet_drawer").slideDown();
				pechetDrawer_open=true;
			}
			else {
				$("#pechet_drawer").slideUp().css('z-index', '');
				pechetDrawer_open=false;
			}
			
			return false;
			
		});
		
		$("#ritchie_toggle").click(function(){
			if(ritchieDrawer_open==false){
				if(lumDrawer_open==true){
					$("#lum_drawer").css('z-index', '');
					$("#lum_drawer").slideUp();
					lumDrawer_open=false;
				}
				else if(jonesDrawer_open==true){
					$("#jones_drawer").css('z-index', '');
					$("#jones_drawer").slideUp();
					patkauDrawer_open=false;
				}
				else if(pechetDrawer_open==true){
					$("#pechet_drawer").css('z-index', '');
					$("#pechet_drawer").slideUp();
					pechetDrawer_open=false;
				}

				$("#ritchie_drawer").css('z-index', '1000');
				$("#ritchie_drawer").slideDown();
				ritchieDrawer_open=true;
			}
			else {
				$("#ritchie_drawer").css('z-index', '');
				$("#ritchie_drawer").slideUp();
				ritchieDrawer_open=false;
			}
			
			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();
					var img = new Image();
					$(img).load(function() {
							$('#loader').append(img);
							$('#loading').fadeOut('slow',function(){$(this).remove();});							
							$(img).fadeIn('slow');
						}).attr({src: backImage[counter], id: "bg_image"});
						$("#bg_image:last").fadeOut().remove();	
					}
				
			
					else {
					$('<div id="loadingStart" class="active"></div>').html("loading...").appendTo('.columnHeader').fadeIn();
					var img = new Image();
					$(img).load(function() {
							$('#loader').append(img);
							$('#loadingStart').fadeOut('slow',function(){$(this).remove();});
							$(img).fadeIn('slow');
						}).attr({src: backImage[counter], id: "bg_image"});
						$("#bg_image:last").fadeOut().remove();
					
				
				}
			}
			return false;
		});
		
		

	
	
	

	

		$(".columnHeader").click(function(){
			if (collapsed == false) {
				$('#wrapper').toggle();
				$(this).css("-webkit-border-bottom-left-radius", "10px");
				$(this).css("-webkit-border-bottom-right-radius", "10px");
				$(this).css("-moz-border-radius-bottomleft", "10px");
				$(this).css("-moz-border-radius-bottomright", "10px");
			}
			else {
				$('#wrapper').toggle();
				$(this).css("-webkit-border-bottom-left-radius","");
				$(this).css("-webkit-border-bottom-right-radius","");
				$(this).css("-moz-border-radius-bottomleft", "");
				$(this).css("-moz-border-radius-bottomright", "");
			}
			collapsed = !collapsed;

			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;
			});  */
		
		function ajaxifyGinger(file){

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

					ajaxifyGinger($(this).attr('href'));

					return false;
				});



		$(".close_overlay").click(function(){

				$(".overlay").css("visibility", "hidden")
				$(".overlay_screen").css("visibility", "hidden")
				return false;
		});




		$("ul.auction_images a").fancybox();






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

});



	

	



