// JavaScript Document


$(document).ready(function(){
	// initialize scrollables

	if (".hscroll"){
		$('.hscroll > .items').cycle();
	}
	if(".srvint"){
		$('.srvint').cycle();
	}
	if('.scrollable'){		
		var items = $('.scrollable > .items');
		var itemChild = items.children();
		var lnth = itemChild.length;  		
		var random = function(){
		    var t = new Date();
		    t = t.getSeconds();
		       
		    if (t > lnth || t == 0){
		        t = Math.floor(Math.random()*lnth + 1);
		    }
		    return t;
		}
		random = random();             
		//var rnd = Math.floor(Math.random()*lnth+1);		
		//if(rnd>lnth){
		    //rnd = rnd-lnth;
		//}        
		        
		    var start = itemChild.slice(random,lnth);
		    var newitem = itemChild.slice(0,random);
		    items.empty();
		    items.append(start);
		    items.append(newitem);
		
		$(".scrollable").scrollable({speed: 1000, circular: true}).autoscroll({ autoplay: true,interval: 6000 });
	}
	//search form
	var text = "search";

	$("#search_txtSearch").attr("value", text);
	
	$("#search_txtSearch").focus(function() {
		$(this).addClass("active");
		if($(this).attr("value") == text) $(this).attr("value", "");
	});

	$("#search_txtSearch").blur(function() {
		$(this).removeClass("active");
		if($(this).attr("value") == "") $(this).attr("value", text);
	});
	
	$('#search_txtSearch').keypress(function(e){
		if(e.which == 13){
	    	$('#search_btnSearch').click();
	    	e.preventDefault();
	    }
	});

	
	$('div.internal_content').jScrollPane({showArrows:true});
	
	//people page accordion effect		
	if(".accordion"){
	    var $accordion = $(".accordion div")
	    if($.cookie("accord") == null){
	        $accordion.delay('2000').hide('slow');
	        $.cookie("accord","notnull",{expire:7});
	    }
	    else{
	        $accordion.hide();
	    }
	    $accordion.prev().click(function(){
	    		$(this).next().toggle('fast');
	    	});  	
	}
	if(".srv"){
		if(".srvcs"){
			$('.srvcs p').cycle();
		}
	}
	if(".address"){
		$(".address a").colorbox({width:"80%", height:"80%", iframe:true});
	}
		
});



// IE6 li pseudo fix

sfHover = function() {
	var sfEls = document.getElementById("listMenuRoot").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

