$j(document).ready(function() {
	
	var rand1 = Math.ceil(11000*Math.random()) + 3000;
	 $j('.slideshow1').cycle({
	 	speed: 2000,
	 	timeout: rand1
	 });
	 
	 var rand2 = Math.ceil(11000*Math.random()) + 3000;
	 $j('.slideshow2').cycle({
	 	speed: 2000,
	 	timeout: rand2
	 });
	 
	 var rand3 = Math.ceil(11000*Math.random()) + 3000;
	 $j('.slideshow3').cycle({
	 	speed: 2000,
	 	timeout: rand3
	 });
	
	$j("#p_contact .accordion").accordion({
		active: 0,
		change: function(e, ui) {
			var i = $j(this).find('.ui-state-active').index()/2;
			//console.log(i);
			$j('#p_contact .map').children().hide();
			$j('#p_contact .map').children(':eq('+i+')').toggle();
		}		
	});
	
	$j("ul#menu>li").each(function(){
		$j(this).children("ul").css("opacity","0");
		$j(this).children("ul").hide();
	});
	
	$j("ul#menu>li").hover(function() {
		$j(this).children("ul").animate({
			opacity: '1'
		},300);
		$j(this).children("ul").show();
	}, function(){
	   $j(this).children("ul").animate({
			opacity: '0'
	   },300);
	   $j(this).children("ul").hide();
	});
	
	
	//$j('.pager ul').children('.textbox:eq(0) a b:first-child').hide();
	
	$j(".accordion").accordion({
		active: false,
		collapsible: true,
		autoHeight: false
	});		
	
	$j('#p_team #sidebar a').mouseenter(function() {
		var id = $j(this).attr('id');
		$j('.team-mouseover').stop(true,true).hide();
		//alert(id);
		$j('.team-mouseover[id='+id+']').stop(true,true).show('fast');
	});
	
	$j('#p_team #sidebar a').mouseleave(function() {
		var id = $j(this).attr('id');			
		$j('.team-mouseover[id='+id+']').stop(true,true).hide();
		$j('.team-mouseover').stop(true,true).hide();
	});	
	
	
	$j('#p_team #sidebar').mouseleave(function() {
		$j('.team-mouseover').hide();
	});	
	
	$j('#p_team #sidebar a').each(function(i){
		var p = $j(this).offset();
		var id = $j(this).attr('id');
		$j('div[rel='+id+']').offset(p);
	});
	
	$j('.press .small-img img').each(function(e){
		var bg = $j(this).attr('src');
		$j(this).parent().css('background','url('+bg+') center center no-repeat');	
	});
	
	$j('#p_press-release.detail .press .small-img').css('background','none');
	
	//if ($j.browser.msie && ($j.browser.version != "7.0")) {
		$j('ul#menu li ul').each(function(i){
			var wparent = $j(this).parents('li.toplevel').width();
			var wthis = $j(this).width();
			var offset = wparent - wthis;
			$j(this).css('left',offset);
			if(i == 0) {
				$j(this).css('left',offset+"px");
			}
		});
	//}
	
	$j("x#p_aboutus #sidebar.news").jCarouselLite({
    	//btnNext: ".next",
    	//btnPrev: ".prev",
    	fx: 'scrollVert',
    	auto: 3000,
    	vertical: true        	
		 });
		 
		 $j('.pagination-top').prependTo('#main');

	   	 
	$j("#p_aboutus #sidebar.news").simplyScroll({
		className: 'vert',
		horizontal: false,
		frameRate: 15,
		speed: 1,
		autoMode: 'loop'
	});		
		
	$j('#pagination a.prev').html('Previous');	
	$j('#pagination a.next').html('Next');	
	
	//$j("#scContent_136").appendTo("#main");
	
	var index2 = $j('.pages a:last-child').index();
	$j('.pager').cycle({
		timeout: 0,
		next: '.next',
		prev: '.prev', 
		pager: '.pages',
		nowrap: 1,
		after: function() {
			var index = $j('.pages a.activeSlide').index();			
			var index2 = $j('.pages a:last-child').index();	
			
			if (index == 0)
				$j('.prev').hide();
			else
				$j('.prev').show();
			
			
			if (index == index2)
				$j('.next').hide();
			else
				$j('.next').show();
		}
	});
	$j('.next').show();
	$j('.prev').hide();
	
	
	$j(".transactions li").each(function(index){
		if(index % 3 == '2' && index != '0') {
			//console.log(index);
			$j(this).after("<div class='clear'>&nbsp;</div>");
		}
	});
	
	$j("li.trans").first().addClass("first");
	//$j("li.trans").wrap('<ul class="desc"></ul>');
	
	var pagerH = $j(".press .pager ul").height();
	$j(".press .pager").css("height",pagerH);
	
	$j("li.historical").parents("body").addClass("historic");
	
	var transUrl = $j("li.nav_transactions li:first-child a").attr("href");
	$j("#menu li.nav_transactions a.menulink").attr("href",transUrl);
});
