$(document).ready(function(){

	//virtual tour stuff	
	var IsiPhone = navigator.userAgent.indexOf("iPhone") != -1 ;
	var IsiPod = navigator.userAgent.indexOf("iPod") != -1 ;
	var IsiPad = navigator.userAgent.indexOf("iPad") != -1 ;
	
	var IsiOS = IsiPhone || IsiPad || IsiPod ;
	
	if(IsiOS)
	{
		$("a[href='http://via.net.au/Functions/TheAEC/blk/Tour.htm']").attr('href', 'http://via.net.au/Functions/TheAEC/iPhone/index.html')
	}else{
		$("#HouseMenuNavLink131, .tour").colorbox({opacity:0.8, iframe:true, innerWidth:1097, innerHeight:462});
	}
	
	$(".seating_plan").colorbox();

	
	$(".menu li:last").addClass("last").css({"background":"none"});
	
	$(".column1 .module_wrap:last").css({"border":"0"})
	
	$(".search .NormalTextBox").attr({ value: 'Enter keyword(s)' }).focus(function(){
		if($(this).val()=="Enter keyword(s)"){
			$(this).val("");
		}
	}).blur(function(){
		if($(this).val()==""){
			$(this) .val("Enter keyword(s)");
		}
	});
		
	
	$(".menu li").hover(function(){
		$(this).children("ul").show();
		$(this).children("a").addClass("active");
	},function(){
		$(this).children("ul").hide()
		$(this).children("a").removeClass("active");
	});
	
	//this sets up the styles for people who have javascript turned on.

	$(".event_item").css({
		"padding":"0px",
		"width":"247px",
		"height":"171px",
		"margin":"0px"
	}).children(".border").show().siblings(".text").css({
		"position":"absolute",
		"bottom":"-27px"
	}).siblings(".title").css({
		"position":"relative"
	});
	
	
	
	
$(".event_item").each(function(i){
	
	/*var durHeight  = $(this).children(".text").children(".duration").height();
	var negative_height = (durHeight + 27) *-1;
	
	if( durHeight == 0 ){
		$(this).children(".border").show().siblings(".text").css({
			"position":"absolute",
			"bottom":negative_height
		});
	};*/
	
	var titleHeight = $(this).children(".text").children(".title").height();
	if (titleHeight > 20){
		$(this).children(".text").children(".title").height("20px");
	};
	
	$(this).hover(function(){
		
		//alert(titleHeight);
		$(this).css({"z-index":"25"});
		$(this).children(".border").animate({
			"width":"247px",
			"height":"171px",
			"left":"-6px",
			"top":"-6px"
		}, 200, 'linear',
			function(){$(this).hide()}			
		);
		$(this).children(".text").animate({
			"bottom":"0px"
		}, 200, 'linear').children(".title").animate({	
			"height":titleHeight	
		}, 200, 'linear');
		
		$(this).children(".text").children(".bg_text2").fadeTo(200, 0.8);
		$(this).children(".text").children(".bg_text").fadeTo(200, 0);
		$(this).parent(".row").css({"z-index":"25"}).siblings(".row").css({"z-index":"20"});
		
	},function(){
		
		$(this).css({"z-index":"20"});
		$(this).children(".border").show().animate({
			"width":"235px",
			"height":"159px",
			"left":"0px",
			"top":"0px"
		}, 200, 'linear',
			function(){$(this).parent(".event_item").css({"z-index":"15"}) }			
		);
		$(this).children(".text").animate({
			"bottom": "-27px"
		}, 200, 'linear').children(".title").animate({	"height":"20px"	}, 200, 'linear');;
		
		$(this).children(".text").children(".bg_text").fadeTo(200, 0.8);
		$(this).children(".text").children(".bg_text2").fadeTo(200, 0);
		$(".row").css({"z-index":"20"})
		
	})
	
});
	
	
	//this is the hover event... 
	
	/*$(".event_item").hover(function(){
		$(this).css({"z-index":"25"});
		$(this).children(".border").animate({
			"width":"247px",
			"height":"171px",
			"left":"-6px",
			"top":"-6px"
		}, 200, 'linear',
			function(){$(this).hide()}			
		);
		$(this).children(".text").animate({
			"bottom":"0px"
		}, 200, 'linear').children(".title").animate({	"height":"auto"	}, 200, 'linear');
		$(this).children(".text").children(".bg_text2").fadeTo(200, 0.8);
		$(this).children(".text").children(".bg_text").fadeTo(200, 0);
		$(this).parent(".row").css({"z-index":"25"}).siblings(".row").css({"z-index":"20"}).siblings
	},function(){
		$(this).css({"z-index":"20"});
		$(this).children(".border").show().animate({
			"width":"235px",
			"height":"159px",
			"left":"0px",
			"top":"0px"
		}, 200, 'linear',
			function(){$(this).parent(".event_item").css({"z-index":"15"}) }			
		);
		$(this).children(".text").animate({
			"bottom":"-45px"
		}, 200, 'linear').children(".title").animate({	"height":"20px"	}, 200, 'linear');;
		$(this).children(".text").children(".bg_text").fadeTo(200, 0.8);
		$(this).children(".text").children(".bg_text2").fadeTo(200, 0);
		$(".row").css({"z-index":"20"})
	})	*/		
	
	
	
	
	
	$(".bg_text").after("<div class='bg_text2'></div>");
		
	//this fades in the items sequentially	
	$(function() { 
	   var $sequence = $(".event_item").hide(), event_item = 0; 
	   (function(){ 
		   $($sequence[event_item++]).fadeIn(250, arguments.callee); 
	   })(); 
	}); 
	
	
	//this adds the correct styling and class for each row and its children events
	
	

	$(".event_item").slice(0,4).wrapAll("<div class='row1 row'></div>");
	$(".event_item").slice(4,8).wrapAll("<div class='row2 row'></div>");
	$(".event_item").slice(8,12).wrapAll("<div class='row3 row'></div>");
	$(".event_item").slice(12,16).wrapAll("<div class='row4 row'></div>");
	$(".event_item").slice(16,20).wrapAll("<div class='row5 row'></div>");
	$(".event_item").slice(20,24).wrapAll("<div class='row6 row'></div>");
	$(".event_item").slice(24,28).wrapAll("<div class='row7 row'></div>");
	$(".event_item").slice(28,32).wrapAll("<div class='row8 row'></div>");	
	$(".event_item").slice(32,36).wrapAll("<div class='row9 row'></div>");	
	$(".event_item").slice(36,40).wrapAll("<div class='row10 row'></div>");	
	$(".event_item").slice(40,44).wrapAll("<div class='row11 row'></div>");	
	$(".event_item").slice(44,48).wrapAll("<div class='row12 row'></div>");	
	$(".event_item").slice(48,52).wrapAll("<div class='row13 row'></div>");	
	$(".event_item").slice(52,56).wrapAll("<div class='row14 row'></div>");	
	
	
	$(".row1").children(".event_item").each(
		function(i){			
			var eventclass = "event"+(i+1)			
			$(this).addClass(eventclass); // adds "event1, event2" etc to each item
			
			$(this).css({
				"position":"absolute",
				"z-index":"15",
				"left":(241*i)
			});			
		}
	);
	
$(".row2").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row3").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row4").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row5").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row6").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row7").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row8").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row9").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row10").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row11").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row12").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row13").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
$(".row14").children(".event_item").each(function(i){var eventclass = "event"+(i+1);$(this).addClass(eventclass);$(this).css({"position":"absolute","z-index":"15","left":(241*i)});});
	
$(".row:last").append("<div class='last_line'></div>");
var amount_of_events = ($(".row:last > * ").size())-1;
var last_row_width = amount_of_events * 247;
$(".last_line").width(last_row_width);

$(".footer").css({"position":"relative"});
	
	
	
$(".row").each(
	function(i){		
		$(this).append("<div style='clear:both;'></div>"); 
	}
);
	

$('#controls').each(function(){		
	//$(this).attr("id","controls");
	var flashHeight = $(this).attr("height");
	var flashWidth = $(this).attr("width");
	$(this).wrap("<div class='flash_controls' isplay='playing' style='width:"+flashWidth+"px;height:"+flashHeight+"px;'></div>");
	$(".flash_controls").append("<div class='controls' style='width:"+flashWidth+"px;height:"+flashHeight+"px;'><span class='play'></span><span class='pause'></span></div>");		
	$(".play").hide();
	$(".pause").hide();
});


$(".controls").click(function(){
	var checkIfPlaying = 	$(".flash_controls").attr("isplay");
	if (checkIfPlaying == "playing"){		
		document.getElementById("controls").StopPlay();
		$(".pause").hide();
		$(".play").show();
		$(".flash_controls").removeAttr("isplay").attr("isplay","paused");
	}else if (checkIfPlaying == "paused"){		
		document.getElementById("controls").Play();
		$(".play").hide();
		$(".flash_controls").removeAttr("isplay").attr("isplay","playing");
	}else{
		//alert('failed somewhere');
	}		
});

$(".controls").hover(overControls, outControls);
function overControls(){
	var checkIfPlaying = 	$(".flash_controls").attr("isplay");
	if (checkIfPlaying == "playing"){
		$(".pause").show();
	}
}
function outControls(){
	var checkIfPlaying = 	$(".flash_controls").attr("isplay");
	if (checkIfPlaying == "playing"){
		$(".pause").hide();
	}
}
	
});

