
//Google Analytics
if (window.location.toString().indexOf('empirestaging') < 0) {
    try {
        var pageTracker = _gat._getTracker("UA-0000000-0");
        pageTracker._trackPageview();
    } 
    catch (err) {
    }
}


$(document).ready(function(){
	

	  // Home Page News and events fader
	  
	if($("div").hasClass('panel')){
		$("div#slider1").cycle({
			  fx:     'fade',
			  speed:  'fast',
			  timeout: 5000,
			  next:   '#news_next',
			  prev:   '#news_prev',
			  fx: 'fade' 
		});
	}
	   

	  
		/** Clears the search box */
		$("#search").click(function(){
		    if ($("#search").val().length >= 1 && $("#search").val() == $('#seach_default').val()) {
		        $("#search").val('');
		    }
		});
		
		$("#search").blur(function(){
		    if ($("#search").val().length == 0) {
		        $("#search").val($('#seach_default').val());
		    }
		});
		
		$("input.gsc-input").click(function(){
		    if ($("input.gsc-input").size() >= 1) {
		        $("input.gsc-input").val('');
		    }
		});
		
    // initialise plugins
    jQuery(function(){
        $('ul.sf-menu').superfish({
            delay: 1000, // one second delay on mouseout
            animation: {
                opacity: 'show',
                height: 'show'
            }, // fade-in and slide-down animation
            speed: 'fast', // faster animation speed
            autoArrows: false, // disable generation of arrow mark-up
            dropShadows: false // disable drop shadows
        });
    });
    
    
    /* Document List Tree 
     $("#document-list").treeview({
     collapsed: true,
     animated: "fast"
     });*/
    
    
    //Error form wrapping
    $(".error_div").parent().addClass("error");
    
    //Applies a border to the checkbox and radio button in FF
    if ($.browser.mozilla) {
      $(".error input[type='checkbox']").addClass("error");
      $(".error input[type='radio']").addClass("error");
      $('input.error').wrap('<span style="border:1px #AA0000 dashed; display:inline-block; margin:4px; vertical-align:middle;"></span>');
    };        
    
    /**
     * This script renders a different random image for the page background
     */
    var theImages = new Array()
    // If images are changed or added, change only this part
    theImages[0] = '/images/random_image/home-dad-mom-girl.jpg'
    theImages[1] = '/images/random_image/home-senior-bike.jpg'
    theImages[2] = '/images/random_image/home-mariachis.jpg'
    theImages[3] = '/images/random_image/home-mom-baby.jpg'
    theImages[4] = '/images/random_image/home-mom-boy-girl.jpg'
    
    var j = 0
    var p = theImages.length;
    var preBuffer = new Array()
    for (i = 0; i < p; i++) {
        preBuffer[i] = new Image()
        preBuffer[i].src = theImages[i]
    }
    
    var whichImage = Math.round(Math.random() * (p - 1));
    var thisImage = theImages[whichImage]
    
    $('.home #main').css({
        'background': 'url(' + thisImage + ') no-repeat top right'
    });
    
    $('.home.spanish #main').css({
        'background': 'url(' + thisImage + ') no-repeat top right'
    });
    
});

