
function expand() {
    $('#flashArea').animate({ height: '529px' }, 500);
    $('#flashArea').addClass('expanded');
}

function collapse() {
    $('#flashArea').animate({ height: '329px' }, 500);
    $('#flashArea').removeClass('expanded');
}

function togglePlayer() {
   
}

function expandPlayer() {
    if ($('#flashArea').hasClass('expanded') !== true) {
        expand();
    }
}


$(document).ready(function(){

	$("#pageMenu li").hover(
			function(){
				if($.browser.msie){
					$(this).find('.megaMenu_2btm').show();
					$(this).find('h4').show();	
				}
				else{
					$(this).find('.megaMenu_2btm').stop(true,true).show("fast");
					$(this).find('h4').stop(true,true).fadeIn("fast");
				}
			}, 
			function (){
				if($.browser.msie){
					$(this).find('.megaMenu_2btm').hide();
					$(this).find('h4').hide();	
				}
				else{
					$(this).find('.megaMenu_2btm').hide("fast");
					$(this).find('h4').fadeOut("fast");
				}
			}
	);
	

	
	//flash player toogle
	$('#toggle').click(function(){
		 if ($('#flashArea').hasClass('expanded') === true) {
				collapse(); $('#toggle').html('+');return false;
			} else {
				expand(); $('#toggle').html('-');return false;
			}
	
	});
	
	
	//put flash player
	$('#player_wrap').flash(   {   // test.swf is the flash document   
		 swf: 'ecoffee-video2.swf', 
		 height: 529, 
		 width: 940, 
		 align: 'middle',
		 play: 'true',
		 loop: 'true',
		 scale: 'showall',
		 wmode: 'transparent',
		 devicefont: 'false',
		 bgcolor: '#000000',
		 menu: 'true',
		 allowScriptAccess:'always',
		 allowNetworking: 'all', 
		 allowFullScreen: 'true',
		 flashvars: 'configurl=http://r.unicornmedia.com/embed/7757a91a-31d9-4a0b-aa99-0b786d910e6b&interface=0'
	  	}   );   


	
	//flash uploader
	if($("#uploadify").length > 0){
		$("#uploadify").uploadify({
			'uploader'       : TEMPLATE_PATH+'/scripts/uploadify.swf',
			'script'         : TEMPLATE_PATH+'/scripts/uploadify.php',
			'cancelImg'      : TEMPLATE_PATH+'/images/cancel.png',
			'buttonImg'		 : TEMPLATE_PATH+'/images/choose_video_file_brown.png',
			'folder'         : 'wp-content/uploads/videos',
			'width'          : 149,
			'height'         : 26,
			'queueID'        : 'fileQueue',
			'auto'           : true,
			'multi'          : true,
			'fileDesc'       : 'You can see only allowed extension files',
			'fileExt'		 : '*.flv;*.mp4;*.mp4v;*.mp4v;*.mp2v;*.mp2s;*.wmv;*.3gp;*.avi;*.mov;*.mpeg;*.mkv',
			'scriptData'	 : {'timestamp': TIME_STAMP},
			'onComplete'  : function (evt, queueID, data, res) {
				
				if($("#q_files").val()=='')
					$("#q_files").val(TIME_STAMP+'_'+data.name);
				else
					$("#q_files").val($("#q_files").val()+','+TIME_STAMP+'_'+data.name);
				
			}
		});
	}
	
	if($('.butn_cont span').length > 0){
		$('.butn_cont span').hover(
				function(){
					$(this).addClass('butn_span_hover').css('background-position','left -91px');
				},
				function(){
					$(this).removeClass('butn_span_hover').css('background-position','left 5px');	
				}
		);	
	}
	
	
	
	if($('#add_comment .butn_brown5').length > 0){
		$('#add_comment .butn_brown5').hover(
				function(){
					$(this).css('color','#056839').css('background-position','left -33px');
				},
				function(){
					$(this).css('color','#3b2313').css('background-position','left 5px');	
				}
		);	
	}

	
 });


function checkQuestion(){

	document.getElementById('errMsg').style.display = 'none';

	var name = document.getElementById('q_name').value;
	var email = trim(document.getElementById('q_email').value);	
	var text = trim(document.getElementById('q_text').value);
	var q_for = trim(document.getElementById('q_for').value);
	var q_files = trim(document.getElementById('q_files').value);

	if( name=='' || email=='' || (text=='' && q_files=='')){
		if(name=='')
			pageTracker._trackEvent("Submit Question - "+q_for, "Error", "Name");
		if(email=='')
			pageTracker._trackEvent("Submit Question - "+q_for, "Error", "Email");
		if(text=='' && q_files=='')
			pageTracker._trackEvent("Submit Question - "+q_for, "Error", "Comment");
		
		//alert('Please complete the required fields (Name, Email).');
		document.getElementById('errMsg').innerHTML = 'Please complete the required fields (Name, Email, Question).';
		document.getElementById('errMsg').style.display = 'block';
		return false;
	}
	else if( !checkEmail(email) ){
		//alert('Please enter a valid email address.');
		pageTracker._trackEvent("Submit Question - "+q_for, "Error", "Email");
		
		document.getElementById('errMsg').innerHTML = 'Please enter a valid email address.';
		document.getElementById('errMsg').style.display = 'block';
		return false;
	}
	
	pageTracker._trackPageview("/events/engage/submit-question-"+q_for+".html")
	
}


function fieldcheck(){
	//alert('alert');	
	document.getElementById('errMsg').style.display = 'none';
	//document.getElementById('sucMsg').style.display = 'none';
	//alert(1);
	
	
	

		var tele = trim(document.getElementById('tele').value);
		var name = trim(document.getElementById('con_author').value);
		var email = trim(document.getElementById('ad_email').value);
		
		
		if( name=='' || email=='' || tele==''){
			
			
			//alert('Please complete the required fields (Name, Email,Telephone).');
			document.getElementById('errMsg').innerHTML = 'Please complete the required fields (Name, Email, Telephone).';
			document.getElementById('errMsg').style.display = 'block';
			return false;
		}
		else if( tele==''){
			//alert('Please type a Comment.');
			document.getElementById('errMsg').innerHTML = 'Please type a Telephone Number.';
			document.getElementById('errMsg').style.display = 'block';
			return false;
		}
		else if( !checkEmail(email) ){
			//alert('Please enter a valid email address.');
			
			document.getElementById('errMsg').innerHTML = 'Please enter a valid email address.';
			document.getElementById('errMsg').style.display = 'block';
			return false;
			}
		else
		{ 
			document.getElementById('sucMsg').innerHTML = 'Thank you, your request was sent successfully. <br /> One of the ecoffee team will be in touch shortlY.';
			document.getElementById('sucMsg').style.display = 'block';
			return true;
		}
	
  }





function checkRequired(){

	document.getElementById('errMsg').style.display = 'none';
	
	if($('#sucMsg').length > 0)
		document.getElementById('sucMsg').style.display = 'none';
	
		//alert('alert');
		var status = document.getElementById('loggedin').value;
		var comment = trim(document.getElementById('comment').value);
		//alert(1);
		
		if( status=='no' ){
		
			var name = trim(document.getElementById('author').value);
			var email = trim(document.getElementById('email').value);
			
			if( name=='' || email=='' ){
			//alert('Please complete the required fields (Name, Email).');
			document.getElementById('errMsg').innerHTML = 'Please complete the required fields (Name, Email).';
			document.getElementById('errMsg').style.display = 'block';
			return false;
		}
		else if( comment=='' ){
			//alert('Please type a Comment.');
			document.getElementById('errMsg').innerHTML = 'Please type a Comment.';
			document.getElementById('errMsg').style.display = 'block';
			return false;
		}
		else if( !checkEmail(email) ){
			//alert('Please enter a valid email address.');
			document.getElementById('errMsg').innerHTML = 'Please enter a valid email address.';
			document.getElementById('errMsg').style.display = 'block';
			return false;
		}
	}
	else{
		//alert('Please type a Comment.');
		if( comment=='' ){
		
			document.getElementById('errMsg').innerHTML = 'Please type a Comment.';
			document.getElementById('errMsg').style.display = 'block';
			return false;
		}
	}
	
	pageTracker._trackPageview("/events/engage/comment.html")
}





function overlay(id){
		$(".TB_overlayBG ").css("opacity","0.75");
		if (typeof document.body.style.maxHeight === "undefined") {//if IE 6
			$("body","html").css({height: "100%", width: "100%"});
			$("html").css("overflow","hidden");
			if (document.getElementById("TB_HideSelect") === null) {//iframe to hide select elements in ie6
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}else{//all others
			if(document.getElementById("TB_overlay") === null){
				$("body").append("<div id='TB_overlay'></div><div id='TB_window'></div>");
				$("#TB_overlay").click(tb_remove);
			}
		}
		
		if(tb_detectMacXFF()){
			$("#TB_overlay").addClass("TB_overlayMacFFBGHack");//use png overlay so hide flash
		}else{
			$("#TB_overlay").addClass("TB_overlayBG");//use background and opacity
		}
		
	tb_position_new();
	$('#'+id).fadeIn();
	if($.browser.msie && $.browser.version=="6.0")
		$('#TB_overlay').show();	
	else	
		$('#TB_overlay').fadeIn();
	$('#TB_window').fadeIn();
	
	
	//$("#new").append($('#signOverlay').children());
}

function overlayClose(id){

	
	$('#'+id).fadeOut();
	if($.browser.msie && $.browser.version=="6.0")
		$('#TB_overlay').hide();	
	else
		$('#TB_overlay').fadeOut();
	$('#TB_window').fadeOut();	
	//tb_remove();
	
	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
}


function tb_position_new() {
	var TB_WIDTH = (481*1) + 30 || 630; //defaults to 630 if no paramaters were added to URL
	var TB_HEIGHT = (522*1) + 40 || 440; //defaults to 440 if no paramaters were added to URL

	$("#TB_window").css({marginLeft: '-' + parseInt((TB_WIDTH / 2),10) + 'px', width: TB_WIDTH + 'px'});
	if ( !(jQuery.browser.msie && jQuery.browser.version < 7)) { // take away IE6
		//$("#TB_window").css({marginTop: 0 - parseInt(this.offsetHeight / 2) + (TBWindowMargin = document.documentElement && document.documentElement.scrollTop || document.body.scrollTop);
		$("#TB_window").css({marginTop: '-' + parseInt((TB_HEIGHT / 2),10) + 'px'});
	}
}


function ltrim(str) { 
	for(var k = 0; k < str.length && isWhitespace(str.charAt(k)); k++);
	return str.substring(k, str.length);
}
function rtrim(str) {
	for(var j=str.length-1; j>=0 && isWhitespace(str.charAt(j)) ; j--) ;
	return str.substring(0,j+1);
}
function trim(str) {
	return ltrim(rtrim(str));
}
function isWhitespace(charToCheck) {
	var whitespaceChars = " \t\n\r\f";
	return (whitespaceChars.indexOf(charToCheck) != -1);
}

function checkEmail(emial){
	var str=emial;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (filter.test(str))
		return true;
	else
		return false;
}

