var maxWidth = 408;
var minWidth = 180;
var selectpage=0;
var navPrev=1;
var ddSel=-1;

$(document).ready(function(){

	
	$('.accordion').accordion();
	$('.toggler').accordion();
	$('.toggy').accordion();
	$('#testimonials_list').accordion({after:true});
	
	
	/*
		old accordion function
	*/
	
	if($('.consH2').length){
	$('.consH2').click(function(){
			thsIndx=$('.consH2').index(this);
			//aniHeight=$('.consCout').eq(thsIndx).children('.consC').height();
			
			$('.consCout').slideUp();//.animate({height:0},{duration:300,queue:false});
						
			if(thsIndx!=ddSel || $('.consCout').eq(thsIndx).height()==0){
				$('.consCout').eq(thsIndx).slideDown();//.animate({height:aniHeight},{duration:300,queue:false});
				ddSel=thsIndx;
				
				if($('.recYourContact').length>0){imgIndent=thsIndx+7;}
				if($('.ourConsultants').length>0){imgIndent=thsIndx+4;}
				
				if($('.ourConsultants').length>0 || $('.recYourContact').length>0){					
					$('#sectionboxes li').eq(selectpage).children('a').animate({opacity:0},{duration:300,queue:false});
					$('#sectionboxes li').eq(selectpage).children('img').fadeOut(300);
					$('#sectionboxes li').eq(selectpage).children('img').eq(imgIndent).fadeIn(300);
				}
			}
			
			//$(this).parent().slideDown();//.animate({height:aniHeight+200},{duration:300,queue:false});
		});
	}
	
	/* */
						   
						   
	$('.testa_con').hide();
	$('.heading_con').corner();
	$('.content').hide();	

		if($('#promotion').length>0){
		$(window).bind("resize",function(){
			$('.pgecontainer').pgeConCen();					   
		});
		$(window).bind("load",function(){
				$('#promotion').PgeMask(function(){
				$('.pgecontainer img, .pgewrapper .pgemask').click(function(){
					$(this).PgeUnloadmask();					
				});				
			});
		});
		}
		
	$(window).bind("load",function(){	
		
		
		/* tool tip */
		$('.tooTipC').animate({opacity:0},{duration:0,queue:false});
		$(window).mousemove(function(e){mLpos=e.pageX-($(window).width()-960)/2-113;$('.tooTipC').css({left:mLpos})});
		
		$('.footerlist li a, #ioh').mouseover(function(){
			thsTxt=$(this).attr('rel');
			$('.tooTipC').css({display:'block'}).animate({opacity:.9},0,function(){
				bVer=jQuery.browser.version;
				if(bVer=='6.0' || bVer=='7.0'){$(this).get(0).style.removeAttribute('filter');}																
			})
			.children('span').text(thsTxt);
		}).mouseout(function(){
			$('.tooTipC').animate({opacity:0},0,function(){
				$(this).css({display:'none'});											   
			});
		});


	});
	
	
	$('.clickhome').click(function(){
		window.location='index.htm';							   
	});
	
	$('.footerlist li a').click(function(){
		thisHref=$(this).attr('href');
		if(thisHref!="" && thisHref!=" " && thisHref!="#"){window.open(thisHref);}
		return false;
	});
	
	$('.txtbox').focus(function(){
		$(this).val("");							
	});
	
	$('.listtxt').click(function(){
		thisIndex=$('.listtxt').index(this);				 
		$('.testa_con').slideUp(300).eq(thisIndex).slideDown(300);
	});
	
	$('#so_contactform').submit(function(){
		$('#post_result').text("Processing...");
		f_name=$('.txtbox').eq(0).val();
		f_emai=$('.txtbox').eq(1).val();
		f_company=$('.txtbox').eq(2).val();
		f_tel=$('.txtbox').eq(3).val();
		f_message=$('.txtbox').eq(4).val();
		
		if(CheckEmail(f_emai) && chkfields(Array(f_name, f_company, f_tel, f_message)))
		{
			$.post("media/php/sndemail.php",{operation: "so_contactform", f1: f_name, f2: f_emai, f3: f_company, f4: f_tel, f5:f_message},function(data){
				$('#post_result').text(data);
				$('.txtbox').val("");
			});
		}
		else
		{
			$('#post_result').text("Please ensure all fields are filled in correctly.");
		}
		
		return false;								  
	});
	
	$('#co_contactform').submit(function(){
		$('#post_result').text("Processing...");
		f_name=$('.txtbox').eq(0).val();
		f_emai=$('.txtbox').eq(1).val();
		f_company=$('.txtbox').eq(2).val();
		f_tel=$('.txtbox').eq(3).val();
		f_message=$('.txtbox').eq(4).val();
		
		if(CheckEmail(f_emai) && chkfields(Array(f_name, f_company, f_tel, f_message)))
		{
			$.post("media/php/sndemail.php",{operation: "co_contactform", f1: f_name, f2: f_emai, f3: f_company, f4: f_tel, f5:f_message},function(data){
				$('#post_result').text(data);
				$('.txtbox').val("");
			});
		}
		else
		{
			$('#post_result').text("Please ensure all fields are filled in correctly.");
		}
		
		return false;								  
	});
	
	/*start shannon*/
	$('#lp_form').submit(function(){
		$('#post_result').text("Processing...");
		f_title=$('.txtbox').eq(0).val(); //chk
		f_name=$('.txtbox').eq(1).val(); //chk
		f_emailaddr=$('.txtbox').eq(2).val(); //chk
		f_cnumber=$('.txtbox').eq(3).val();
		
		if(CheckEmail(f_emailaddr) && chkfields(Array(f_name, f_cnumber)))
		{
			$.post("media/php/sndemail.php",{operation: "lp_form", f1: f_title, f2: f_name, f3: f_emailaddr, f4: f_cnumber},function(data){
				$('#post_result').text(data);
				$('.txtbox').val("");
				$('.downloadlink').show();				
			});
		}
		else
		{
			$('#post_result').text("Please ensure all fields are filled in correctly.");
		}
		
		return false;								  
	});
	/*end shannon*/
		
		$('#rec_form').submit(function(){
		$('#post_result').text("Processing...");
		
		f_title=$('.txtbox').eq(0).val();
		f_name=$('.txtbox').eq(1).val(); //chk
		f_company=$('.txtbox').eq(2).val(); //chk
		f_address=$('.txtbox').eq(3).val();
		f_postcode=$('.txtbox').eq(4).val();
		f_tel=$('.txtbox').eq(5).val();
		f_mob=$('.txtbox').eq(6).val();
		f_email=$('.txtbox').eq(7).val(); //chk
		f_vacancy=$('.txtbox').eq(8).val(); //chk
		f_urgency=$('.txtbox').eq(9).val();
		f_bttc=$('.txtbox').eq(10).val();
		f_comments=$('.txtbox').eq(11).val();
		
		if(CheckEmail(f_email) && f_name!="" && f_company!="" && f_vacancy!="")
		{
			$.post("media/php/sndemail.php",{operation: "re_form", f1: f_title, f2: f_name, f3: f_company, f4: f_address, f5: f_postcode, f6: f_tel, f7: f_mob, f8: f_email, f9: f_vacancy, f10: f_urgency, f11: f_bttc, f12: f_comments},function(data){$('#post_result').text(data);
																																																																				
			$('.txtbox').val("");
			
			});
		}
		else
		{
			$('#post_result').text("Please ensure all fields are filled in correctly.");
		}
		
		return false;								  
	});
	
	
	
	$('#rec_form2').submit(function(){
		return false;								  
	});
	
	//left navigation control
	$('#navigation li a').click(function(){
		thisIndx=$('#navigation li a').index(this);
		if(thisIndx!=navPrev){
			$('.content').slideUp();
			$(this).parent().parent().children().children().removeClass('current');
	
			$(this).addClass('current');
			clicked_on = $(this).parent().parent().children().children().index(this)-1;
			
			$(this).parent().parent().parent().children('#contentholder').children().eq(clicked_on).slideDown('normal',function(){
				/*thisheight=$(this).height()+10;
				$(this).css("height",thisheight+"px");*/
				imgInd=thisIndx-1;
				
				$('#sectionboxes li').eq(selectpage).children('a').animate({opacity:0},{duration:300,queue:false});
				$('#sectionboxes li').eq(selectpage).children('img').fadeOut(300);
				$('#sectionboxes li').eq(selectpage).children('img').eq(imgInd).fadeIn(300);
				
			});
			navPrev=thisIndx;
		}
		return false;		
	});
	
	
	//top navigation control
	$('#sectionboxes li').mouseover(function(){
		$(this).children("a").eq(1).animate({opacity:0},{duration: 500, queue: false});
		$(this).children("a").eq(0).animate({opacity:1.0},{duration: 500, queue: false});
		expand($(this).children("a"));
	});
	
	$('#sectionboxes li').mouseout(function(){
		
		thisindex=$('#sectionboxes li').index(this);
		if(thisindex!=selectpage)
		{
			$(this).children("a").eq(0).animate({opacity:0},{duration: 500, queue: false});
			$(this).children("a").eq(1).animate({opacity:1.0},{duration: 500, queue: false});
		}
		
		$('#sectionboxes li').animate({width: "237px"},{queue: false});
		if(selectpage<9){expand($('#sectionboxes li').eq(selectpage).children("a"));}
	});
	
	
	
	
	
});


	function expand(element) 
	{
		//animate all elements to minimum
		
		$('#sectionboxes li').animate({
			width: minWidth
		},{queue: false});
		
		//animate hovered element to full
		$(element).parent().animate({
			width: maxWidth
		},{queue: false});	
		
	}
	
	function expandselected()
	{
		$('#sectionboxes li').eq(selectpage).children("a").eq(1).animate({opacity:0},{duration: 500, queue: false});
		expand($('#sectionboxes li').eq(selectpage).children("a"));
	}
	
	
	
	function CheckEmail(inputemail) {
		AtPos = inputemail.indexOf("@");
		StopPos = inputemail.lastIndexOf(".");
	
		if (AtPos == -1 || StopPos == -1)
		{
			return false;
		}
		else
		{
			return true;	
		}
	
	}
	
	function chkfields(inparray)
	{
		j=0;
		for (var i = 0; i < inparray.length; i++) 
		{	
			if(inparray[i]!="")
			{
				j++;
			}
		}
		if(j==inparray.length)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	function ValidateFields()
	{
		j=0;
		$('.txtbox').each(function(i){
			if($(this).val()!="")
			{
				j++;	
			}
		});
		
		if(j==$('.txtbox').size()-1)
		{
			return true;	
		}
		else
		{
			return false;
		}
	}
	
	function AniHead()
	{
		$('.defaultheading').eq(0).animate({opacity:.1},1500,function(){
			$(this).animate({opacity:1},1500,function(){
				//AniHead();							 
			});
		});
	}
