$(document).ready(function(){
	$('#content .slider SPAN').css('display', 'block');
	
	$("INPUT.auto-hint").bind("click", function() {
	    $(this).select();
	});			
	
    $(".quick-enquiry").fancybox({
        'titlePosition'		: 'inside',
        'transitionIn'		: 'none',
        'transitionOut'		: 'none'
    });
	
//	$('INPUT.auto-hint').each(function(i, el){
//        if($(this).val() == ''){
//            $(this).val($(this).attr('title'));
//        }
//        $(el).focus(function(){
//            if ($(this).val() == $(this).attr('title')) {
//                $(this).val('');
//            }       
//        });
//        $(el).blur(function(){
//            if ($(this).val() == '') {
//                $(this).val($(this).attr('title'));
//            }
//        });
//    });

	if ($('#slide').length>0) {
		$('#slide').cycle({ 
			fx:     'fade', 
			speed:  500, 
			timeout: 0, 
			next:   '#next', 
			prev:   '#prev' 
		});
	}
	
	$('.tab UL LI A').hover(function(){
		if ($(this).parent().next('LI').children('A').hasClass('active')) {
			$(this).parent().children('A').children('SPAN.bg').css('display','none');
		}
		if ($(this).parent().prev('LI').children('A').hasClass('active')) {
			$(this).parent().prev('LI').children('A').children('SPAN.bg').css('display','none');
		}
		
	},function(){
		if ($(this).parent().next('LI').children('A').hasClass('active')) {
			$(this).parent().children('A').children('SPAN.bg').css('display','block');
		}
		if ($(this).parent().prev('LI').children('A').hasClass('active')) {
			$(this).parent().prev('LI').children('A').children('SPAN.bg').css('display','block');
		}
	});
	
	var currentTab = $('.tab UL LI A.active').attr('rel');
	$('.tabs-box .item-box').css('display','none');
	$('#'+ $('.tab UL LI A.active').attr('rel')).css('display','block');	
	
	$('.tab UL LI A').click(function(){
		$('.tab UL LI A.active').removeClass('active');
		$(this).addClass('active');
		
		var that = $(this); // needed to maintain scope in callback function
		var currentTabNum = parseInt(currentTab.replace('tab',''));
		var newTabNum = parseInt($(this).attr('rel').replace('tab',''));
		
		if (currentTabNum != newTabNum) {   // don't do this if clicked tab = current tab
		    if (currentTabNum < newTabNum) {
		        // GOING UP
		        $('#'+ $(this).attr('rel')).fadeIn(300, function() { // fade in new
		            $('#' + currentTab).css("display","none"); // hide old
		            currentTab = that.attr('rel');
		            $(that).children('SPAN.bg').css('display','block');
		        });
	        }
	        else {
	            // GOING DOWN
	            $('#'+ $(this).attr('rel')).css("display","block"); // show new underneath
	            $('#' + currentTab).fadeOut(300); // hide current
    	        
	            currentTab = $(this).attr('rel');
	            $(this).children('SPAN.bg').css('display','block');	 
	        }
        }
	});
	
});

function testValid(frm) {
    var bValid = true;
    
    if ((frm.txtSearch.value=="") || (frm.txtSearch.value=="Start Search") || (frm.txtSearch.value.toString().replace(/^\s+/, '').length<4)) {
        bValid = false;
        frm.txtSearch.focus();
        alert("Please enter a search term of 4 characters or more")
    }
    
    return bValid;
}
