/*
	@Peter Rowland
	@Author reactive.com
	@March 2010
*/
$(document).ready(function() {
	
	 //Force ie7 to behave
	 if($('.pbody .bodyRight img').height() == 233){ $('.pbody:not(.subBody)').height(233); }
	 
	 
	 $(".keylinelinkItem").hover(function() { 
        $(this).parent("span").addClass("active-hover"); 
    }, function() { 
        $(this).parent("span").removeClass("active-hover"); 
    });   
	   
	 
	 $('.default .crossFade img:gt(0)').hide();
     $('.default .crossFadeHeadings img:gt(0)').hide();


    setInterval(function(){
        $('.default .crossFade :first-child').fadeOut(3000).next('img').fadeIn(3000).end().appendTo('.crossFade');
        $('.default .crossFadeHeadings :first-child').fadeOut(3000).next('img').fadeIn(3000).end().appendTo('.crossFadeHeadings');
    }, 14000); 
	
	/* 1.01 Gallery Live Query*/
	$('#galleryPrevious a').livequery(function(){ 
	    $(this).fadeTo('fast', 0.5);
    // use the helper function hover to bind a mouseover and mouseout event 
        $(this).hover(function() { 
                $(this).fadeTo('fast', 0.8); 
            }, function() { 
                $(this).fadeTo('fast', 0.5); 
            }); 
    }, function() { 
        // unbind the mouseover and mouseout events 
       $(this).unbind('mouseover');
       $(this).unbind('mouseout'); 
    });
    
    $('#galleryNext a').livequery(function(){ 
	    $(this).fadeTo('fast', 0.5);
    // use the helper function hover to bind a mouseover and mouseout event 
        $(this).hover(function() { 
                $(this).fadeTo('fast', 0.8); 
            }, function() { 
                $(this).fadeTo('fast', 0.5); 
            }); 
    }, function() { 
        // unbind the mouseover and mouseout events 
        $(this).unbind('mouseover').unbind('mouseout'); 
    });
	
	/* 1.02 Apply Table Row Colours */
	$('.content .wysiwygArea table').each(function(){
		$('tr', this).each(function(i){
			if (i % 2 !== 0){$(this).addClass("odd");}
		});
	});
	
	/* 1.03 Gallery Actions */
	$(".moduleGallery ul li.item a").hover(
	  function () {
	    $(this).parent().parent().addClass("itemAction");
		$(this).siblings(".mediaAction").fadeIn(500);
	 },function () {
		$(this).parent().parent().removeClass("itemAction");
		$(this).siblings(".mediaAction").fadeOut(300);
	 });
	
	
	/* Navigation */
	$("#subNav li.Level01").hover(function() {
	    $("#subNav li ul").hide();
	    $("ul", this).show();
	});
	
	$("#subNav").bind("mouseleave", function(e) {
        $("#subNav li ul").hide();
        $("#subNav li.active ul").show();
    });
    
	
	$("#subNav li.active ul").show();
	$("#subNav li:last").addClass("last");
	
	/* 1.04 Jquery Date UI*/
	$(".jqryDateField input").datepicker({
			showOn: 'button',
			buttonImage: '../Images/buttons/calendar.gif',
			buttonImageOnly: true, 
			dateFormat: 'dd/mm/yy'
	});
    
    
    if ($(".jqryDateField input").val()==""){
        $(".jqryDateField input").val('dd/mm/yyyy').addClass("example");
    }
    $(".jqryDateField input").focus(function(){
        if ($(this).val() == "dd/mm/yyyy"){
            $(this).val("").removeClass('example');
        }
    });
    
    $('input.submitButton').click(function(){
        if($('.jqryDateField input').val()=="dd/mm/yyyy"){
            $('.jqryDateField input').val("");
        }
    });
    
    $(".ui-datepicker-trigger").click(function(){
       $(this).siblings("input").addClass("example_overide");
    });
	
	/* 1.05 Tile Matching*/
	var heightMaxRowOne = 0;
	var heightMaxRowTwo = 0;
	var h3MaxHeightRowOne = 0;
	var h3MaxHeightRowTwo = 0;
	var thumbLisitingMax = 0;
	
	//Find Heighest Heading
	$('ul.jquerySetTiles li.tile h3').each(function(i){
		if (i < 4){if ($(this).height() > h3MaxHeightRowOne){h3MaxHeightRowOne = $(this).height();}}
		if (i > 3){if ($(this).height() > h3MaxHeightRowTwo){h3MaxHeightRowTwo = $(this).height();}}
	});
	
	//Set all headings to match heighest
	$('ul.jquerySetTiles li.tile h3').each(function(i){
		if (i <= 3){$(this).height(h3MaxHeightRowOne-10);}
		if (i >= 4 && i < 8){$(this).height(h3MaxHeightRowTwo-10);}
	});

	//Find Heighest Tile
	$('ul.jquerySetTiles li.tile a.button').each(function(i){
		if (i < 4){if ($(this).height() > heightMaxRowOne){heightMaxRowOne = $(this).height();}}
		if (i > 3){if ($(this).height() > heightMaxRowTwo){heightMaxRowTwo = $(this).height();}}
	});
	
	//Set all tiles to match heighest tile
	$('ul.jquerySetTiles li.tile a.button').each(function(i){
		if (i <= 3){$(this).height(heightMaxRowOne);}
		if (i >= 4 && i < 8){$(this).height(heightMaxRowTwo);}
	});
	
	//Find Heighest Tile
	$('ul.venueListing li a.thButton').each(function(i){
		if ($(this).height() > thumbLisitingMax){thumbLisitingMax = $(this).height();}
	});
	
	//Set all tiles to match heighest tile
	$('ul.venueListing li a.thButton').each(function(i){$(this).height(thumbLisitingMax);
	});
	
	
	/* 1.06 Banner Hover*/
	var imgTxtH = $("a.bodyRight .imageRolloverTxt").height() + 15;
	$("a.bodyRight .imageRollover").css({'opacity': 0.6});
	$("a.bodyRight .imageRollover").height(imgTxtH);
	$("a.bodyRight").hover(
	  function () {
		$('.imageRollover', this).fadeTo(300,0.9);
	  },
	  function () {
		$('.imageRollover', this).fadeTo(300,0.6);
	  }
	);
	
	/* 1.07 Tile Hover*/
	
	$("a.tilefeatureLink").hover(
	  function () {
		$('li.tile a.button').fadeTo(600,1.0);
		tileHitState = 1;
	 });
	
	var tileHitState = 0;
	var tileHitState1 = 0;
	$("ul.tileHolder").mouseenter(function(){tileHitState = 1;}).mouseleave(
	  function(){
		  tileHitState = 0;
		  $('li a.button').fadeTo(600,1.0);
	});
    $("ul.venueListing").mouseenter(function(){tileHitState1 = 1;}).mouseleave(
	  function(){
		  tileHitState1 = 0;
		  $('li a.thButton').fadeTo(600,1.0);
	});
	
	$("li.tile a.button").hoverIntent({
		sensitivity: 3, 
		interval: 0, 
		over: tileOn, 
		timeout: 0, 
		out: tileOff
	});
	
	$("ul.venueListing a.thButton").hoverIntent({
		sensitivity: 3, 
		interval: 0, 
		over: tileOn1, 
		timeout: 0, 
		out: tileOff1
	});
	
	function tileOn(){  
		$(this).addClass("pr-active-hover");
		//alert(tileHitState);
		if(tileHitState == 1){
			$("li.tile a.button:not(.pr-active-hover)").fadeTo(500,0.7);
			$(this).fadeTo(500,1.0);
			tileHitState = 0;
		}else{
			$("li.tile a.button:not(.pr-active-hover)").fadeTo(200,0.7);
			$(this).fadeTo(200,1.0);
		}
	}
	function tileOff(){ 
		$(this).removeClass("pr-active-hover");
	}
	
	function tileOn1(){  
		$(this).addClass("pr-active-hover");
		//alert(tileHitState);
		if(tileHitState1 == 1){
			$("li a.thButton:not(.pr-active-hover)").fadeTo(500,0.7);
			$(this).fadeTo(500,1.0);
			tileHitState1 = 0;
		}else{
			$("li a.thButton:not(.pr-active-hover)").fadeTo(200,0.7);
			$(this).fadeTo(200,1.0);
		}
	}
	function tileOff1(){ 
		$(this).removeClass("pr-active-hover");
	}

	
	
	/* 1.08 QnA Accordion*/
	$('.jqryAccordion').accordion({'header': "h4", 'autoHeight': false});
	
	
}); //End Document Ready

/* 2.01 Cufon/Sifr Replace*/
 Cufon.replace('h1,h2,h3');






