	$(document).ready(
		function(){
			addMenuClose('#leftmenu',false);
			addSubMenuPop('.popmenu','.indrop');
			newsBlogScroll();
			CGScroll();		
	});
	
function fadeMe(){
$('#ul-section-scroll').innerfade({
		animationtype: 'fade',
		speed: 500,
		timeout: 6000,
		type: 'sequence',
		containerheight: '140px'
	});	
	
}


var CGTextTime=3000;
var CGItems=0;
var CTObj;
var CGPointer=1;

function CGScroll(){
	CTObj=$('#CGScroll h6');
	CGItems=CTObj.size();
	setTimeout('CGScrollTime()',CGTextTime);
}

function CGScrollTime(){
	$('#CGScroll h6:visible').fadeOut('slow',CGScroll2());

}

function CGScroll2(){
	CTObj.eq(CGPointer).fadeIn('slow',CGScroll3());

}

function CGScroll3(){
	CGPointer++;
	if(CGPointer>=CGItems){
		CGPointer=1;
	}
	setTimeout('CGScrollTime()',CGTextTime);		
}


tickerTime=2000;
newsItems=0;
newsPos=1;
blogItems=0;
blogPos=1;
blogornews='news';

function newsBlogScroll(){
	newsItems=$('.tick-news').size();
	blogItems=$('.tick-blog').size();
	setTimeout('newsBlogTime()',tickerTime);
}

function newsBlogTime(){
	if (blogornews == 'news') {
		newsPos++;
		if (newsPos > newsItems) {
			newsPos = 1;
		}
		$('.tick-news:visible').fadeOut();
		$('#blogtick-news-' + newsPos).fadeIn();
		blogornews='blog';
	}
	else {
		blogPos++;
		if (blogPos > blogItems) {
			blogPos = 1;
		}
		$('.tick-blog:visible').fadeOut();
		$('#blogtick-blog-' + blogPos).fadeIn();
		blogornews='news';
	}
	setTimeout('newsBlogTime()',tickerTime);
}



	
	


	
	var menuProgress=false;	

	function addMenuClose(inClass,showPanel){
		$(inClass+' h3').css({cursor:'pointer'});
		$(inClass+' h3').next().hide();
		$lastMenu=readCookie('menuopen');
		if($lastMenu!=''){
			$('#'+$lastMenu).next().show();
		}		

		$(inClass+' h3.expand').bind('click',function(e){
			createCookie('menuopen',$(this).attr('id'),1);
			cPanel=$(this).next();
			if(cPanel.css('display')=='none' && !menuProgress){
				menuProgress=true;

				$(inClass+' h3:visible').next().slideUp('fast');
				id=$(this).attr('id');
				$('.indrop').hide();
				if(showPanel){
					$('.lockpanel:visible').slideUp();
					
					$('#index-'+id).show();							
					
				}

				cPanel.show('fast',function(){menuProgress=false;});						
			}

		});
	}
	


	
	var popTimer;
	
	
	
	function addSubMenuPop(inClass,subClass){
		$(inClass).css({cursor:'pointer'});
		$(inClass).next().addClass('popout');
		$(inClass).bind('mouseenter',function(e){
			$('.indrop').hide();
			if(popTimer){
				clearTimeout(popTimer);
			}
			cPanel=$(this).next();
			p1=$(this).position();
			ttop=p1.top;
			if(ttop<30){ttop=0};
			cPanel.css('top',ttop);
			cPanel.css('zIndex','999');
			cPanel.css('left',p1.left+165);
			cPanel.show();	
			dx=(cPanel.height()/2)-12;
			ttop=p1.top-dx;
			cPanel.css('top',ttop);
								
			
		});
		$(inClass).bind('mouseleave',function(e){
			cPanel=$(this).next();
			popTimer=setTimeout('closePop()',300);
			
		});	
		
		$(subClass).bind('mouseenter',function(e){
			if(popTimer){
				clearTimeout(popTimer);
			}
		});	
		
		$(subClass).bind('mouseleave',function(e){
			if(popTimer){
				clearTimeout(popTimer);
			}
			popTimer=setTimeout('closePop()',300);
		});					
	}
	
	function closePop(cPanel){
		$('.indrop').hide();

		
	}
	
	function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}



function loadWork(inId){
	if($('#editinprogress').text()!='edit'){
		$('#ourworkwrap').slideUp('slow');
		$('#ourworkdetails').slideDown('slow');
		var cache=Math.floor(Math.random()*10000)
		$('#ourworkdetails').load('../sections/_work.php?id='+inId+'&cache='+cache);
		return false;		
	}else{
		return true;
	}

}

function showProjects(){
	loading('ourworkdetails');
	$('#ourworkwrap').slideDown('slow');
	$('#ourworkdetails').slideUp('slow');
	
}

function loading(inId){
	$('#'+inId).html('<div id="loading"></div>');
	$('#loading').css({marginLeft:220});
}
	

	
