var ajfile = '/include/aj.php';
var _sDelimiter = '||:|:||';


$(document).ready( function(){
	$('#green-logo,.green-link').mouseover( function(){
		$('#green-overlay').stop().fadeIn();								 
	});
	
	$('#green-overlay').hover( function(){
		//$(this).stop().fadeOut();								 
	},
	function(){
		$(this).stop().fadeOut();								 
	});
	
	$('.green-link').click( function(){
		return false;					 
	});
	
	
	$('.show-icap-video').click( function(){
		$('.icap-video').slideDown();
		return false;					 
	});
	
 
	
});

GMAPS = {
	load : function() {
		if (GBrowserIsCompatible()) {
			var map = new GMap2(document.getElementById("locate_gmap"));
			map.addControl(new GLargeMapControl());
			map.addControl(new GMapTypeControl());
			map.setCenter(new GLatLng(40.714462,-73.741393), 10);
			var point = new GLatLng(40.722462,-73.441393);
			var marker = this.createMarker(point,'<div><strong>EEG Enterprises, Inc.</strong><br />586 Main Street<br />Farmingdale, NY 11735<br />516-293-7472</div>')
			map.addOverlay(marker);
			
			var point2 = new GLatLng(40.704083, -73.986762);
			var marker2 = this.createMarker(point2,'<div><strong>Brooklyn Office</strong><br />20 Jay Street, Suite 736<br />Brooklyn, NY 11201<br />516-293-7472</div>')
			map.addOverlay(marker2);
			
			
		}
	}
	,
	createMarker : function(point,html) {
	    var marker = new GMarker(point);
		GEvent.addListener(marker, "mouseover", function() {
			marker.openInfoWindowHtml(html);
		});
		return marker;
	}
}


 
_xBooth = {
	
	isIE6: false,
	init : function(){		
		
		//if ( ($.browser.msie && $.browser.version < 7))
		//	this.isIE6 = true;

	 
			$(".virtual-booth .booth-col1 a").each( function(){		
					 						 
				var l_nDot = parseInt( $(this).attr('class').substr(4));
			
				$(this).click( function(){
					_xBooth.showOverlay(l_nDot);
					return false;
				});
								
				$(this).easyTooltip( {
				 useElement:"dot"+l_nDot,
					   yOffset:50,
					   xOffset:-60
					   });
				});
		
		 
       		
   	
			
			$('.booth-col1 a').hide();
			$('.dot-0').hide();
			//setTimeout( "_xBooth.isReady()",2000);
			//this.showOverlay(3);
			//_xBooth.videoDone();
			//$(".virtual-booth").pngFix(); 
			
	
	},
	
	videoDone: function() {
		//alert('done');
		$('#thebooth').show();
		$('#thebooth-fobj').hide();
		$('.booth-col1 a').fadeIn("slow");
		$('.dot-0').fadeIn("slow");
		//$('#thebooth-fobj').empty();
		 
	},
	
	  
	showInfo : function(){
		$('#overlay-content .side-nav li').removeClass('active');
		$('#overlay-content .side-nav .showinfo').parent('li').addClass('active');
		$('#overlay-content .photo-holder').fadeOut("fast");
		$('#overlay-content .info-holder').fadeIn("fast");
		
	},
	
	showPhotos : function(){
		$('#overlay-content .side-nav li').removeClass('active');
		$('#overlay-content .side-nav .showphotos').parent('li').addClass('active');
		$('#overlay-content .info-holder').fadeOut("fast");
		$('#overlay-content .photo-holder').fadeIn("fast");
	},
	
	showOverlay : function(p_nVal){
		l_sExtra = '';
		if(p_nVal == 3){
			l_sExtra = '<div class="welcome-form-holder">'+              
              '<div class="welcome-thankyou">'+  
             	'Thank you for your message.'+  
             '</div>'+  
            '<div class="welcome-form">'+  
           	  '<form action="/" id="form-booth-welcome" onsubmit="javascript:return _xBooth.submitForm(\'form-booth-welcome\')">'+  
              '<label>Name:</label>'+  
               '<input name="f_name" type="text" id="f_name" accesskey="1" maxlength="80" title="Name" />'+  
               '<div class="clear"></div>'+  
               '<label>Company:</label>'+  
               '<input name="f_company" type="text" id="f_company" accesskey="1" maxlength="150" title="Company" />'+  
               '<div class="clear"></div>'+  
               '<label>Phone:</label>'+  
               '<input name="f_phone" type="text" id="f_phone" accesskey="1" maxlength="50" title="Phone" />'+  
               '<div class="clear"></div>'+  
               '<label>Email:</label>'+  
               '<input name="f_email" type="text" id="f_email" accesskey="2" maxlength="150" title="Email" />'+  
               '<div class="clear"></div>'+  
               '<label>Product interested in:</label>'+  
               '<textarea name="f_interest" id="f_interest" accesskey="1" title="Product interest" ></textarea>'+  
               '<div class="clear"></div>'+  
               '<a href="javascript:void(0)" onmousedown="javascript:_xBooth.submitForm(\'form-booth-welcome\')" class="booth-submit">Submit</a>'+  
               '</form>'+  
          '</div>'+  
          '</div>';
		}
		
		$('#overlay-content').html('<div class="populated-content-inner">' + $('#overlay-content-'+p_nVal).html().replace(/~extra~/,l_sExtra) + ' </div>');
		$('#overlay-content .photo-holder').hide();
		$('#booth-overlay-holder').show();
		$('#overlay-content .info-holder').show();
		$("#overlay-content .showinfo").click( function(){ 
			_xBooth.showInfo(); 	
			return false;
			}
		);
		
		$("#overlay-content .showphotos").click( function(){ 
			_xBooth.showPhotos(); 	
			return false;
			}
		);
		
		$('#overlay-content-bg').css('opacity','0.92');
		//$('#overlay-content-bg').pngFix()

		$('#booth-overlay').show().css('top','-900px').animate( { top:'0px'},300)
		//.animate( { top:'1px', opacity:'.999999'},300, function(){ if(_xBooth.isIE6){ $('.virtual-booth').hide(); } })
	},
	
	hideOverlay : function(){
		//$('#booth-overlay').hide();
		 if(_xBooth.isIE6){ $('.virtual-booth').show(); }
		$('#booth-overlay').animate( { top:'-900px' },300, function(){ $('#booth-overlay-holder').hide(); });
		//$('#booth-overlay').fadeOut('fast');
		//$('#booth-overlay').animate( { top:'1000px' },500);	
	},
	
	submitForm : function(p_sForm){
		
		var l_bValid = true; 		 $('#'+p_sForm+' input').removeClass('focus-field');
		  
		 
		  
		 $('#'+p_sForm+' input').each( function(){
			
			if( $(this).attr('accesskey') == 1){
				if(_xUtils.checkEmpty( $(this).val() )){
					alert('Please enter: ' +  $(this).attr('title'));
					$(this).addClass('focus-field');
					$(this).focus();
					l_bValid = false;
					return false;							   
					}
			
			}else if( $(this).attr('accesskey') == 2){
				if(!_xUtils.checkEmail( $(this).val() )){
					alert('Please enter a valid ' +  $(this).attr('title'));
					$(this).addClass('focus-field');
					$(this).focus();
					l_bValid = false;
					return false;							   
					}
			
			}
			
			});
		
		if(!l_bValid)
			return false;
			
		$('#'+p_sForm+' textarea').removeClass('focus-field');
		$('#'+p_sForm+' textarea').each( function(){
			if( $(this).attr('accesskey') == 1){
				if(_xUtils.checkEmpty( $(this).val() )){
					alert('Please enter: ' +  $(this).attr('title'));
					$(this).addClass('focus-field');
					$(this).focus();
					l_bValid = false;
					return false;							   
					}
			}
		});
		
		
		if(!l_bValid)
			return false;
	 
		var l_aSendingVars = new Array();
		$('#'+p_sForm+' textarea,#'+p_sForm+' input').each( function(){
			l_aSendingVars.push( Base64.encode( $(this).attr('id') + _sDelimiter + $(this).val()));				
		});
		
		$.ajax({
		  type: "POST",
		  url: ajfile,
		  data: "a=boothEmail&args="+l_aSendingVars.join(','),
		  success: function(msg){
			  eval(msg);
		  }
		});
		 
		
		return false;	
	}
	
}





_xUtils = {
	
	   
	checkEmpty : function(p_sVal){
		l_sVal = escape(p_sVal);
		l_sVal = l_sVal.replace(/\s*((\S+\s*)*)/, "$1");
		l_sVal = l_sVal.replace(/((\s*\S+)*)\s*/, "$1");
		return l_sVal.length < 1;
	}
	,
	checkEmail : function(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){ return false }
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ return false }
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ return false }
		if (str.indexOf(at,(lat+1))!=-1){ return false }
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ return false }
		if (str.indexOf(dot,(lat+2))==-1){ return false }
		if (str.indexOf(" ")!=-1){ return false }
		return true					
	},
	checkAlphaNumeric : function(p_sVal){
		return !(/[^a-zA-Z0-9]/.test(p_sVal));	
	}
}

var Base64 = {

    // private property
    _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

    // public method for encoding
    encode : function (input) {
        var output = "";
        var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
        var i = 0;

        input = Base64._utf8_encode(input);

        while (i < input.length) {

            chr1 = input.charCodeAt(i++);
            chr2 = input.charCodeAt(i++);
            chr3 = input.charCodeAt(i++);

            enc1 = chr1 >> 2;
            enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
            enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
            enc4 = chr3 & 63;

            if (isNaN(chr2)) {
                enc3 = enc4 = 64;
            } else if (isNaN(chr3)) {
                enc4 = 64;
            }

            output = output +
            this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
            this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

        }

        return output;
    },

    // public method for decoding
    decode : function (input) {
        var output = "";
        var chr1, chr2, chr3;
        var enc1, enc2, enc3, enc4;
        var i = 0;

        input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

        while (i < input.length) {

            enc1 = this._keyStr.indexOf(input.charAt(i++));
            enc2 = this._keyStr.indexOf(input.charAt(i++));
            enc3 = this._keyStr.indexOf(input.charAt(i++));
            enc4 = this._keyStr.indexOf(input.charAt(i++));

            chr1 = (enc1 << 2) | (enc2 >> 4);
            chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
            chr3 = ((enc3 & 3) << 6) | enc4;

            output = output + String.fromCharCode(chr1);

            if (enc3 != 64) {
                output = output + String.fromCharCode(chr2);
            }
            if (enc4 != 64) {
                output = output + String.fromCharCode(chr3);
            }

        }

        output = Base64._utf8_decode(output);

        return output;

    },

    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while ( i < utftext.length ) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}