// JavaScript Document
 var popUpBorder = 100;

 $(document).ready(function () {


$(".bookmark ul li a").each(function(){
		$(this).attr("href", $(this).attr("href") + document.location + "&title="+document.title );	   
			   });

	/*				 
$(function() {
//$.fn.media.mapFormat('avi','quicktime');
        // this one liner handles all the examples on this page
        $('a.media').media();
    });	
*/
$("#video").click(function(){
		$('#flashapp').playVideo();				   
						   
 });

if($("#vidLink").length){
$("#vidLink").fancybox({
	    'padding'           : 0,
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none'
	});
}
var recordingSessionInProgress = false;

		// $("#popUpContent").center();
		var left = $(window).width() /  2;
		 left = left - $("#diagram").width() / 2
		 $("#diagram").css('margin-left',left )
		
		 $("#popUpContent").css('position', 'absolute'); 
                                var left = ($(window).width() - $("#popUpContent").outerWidth())/2+$(window).scrollLeft();
                                 
                                 $("#popUpContent").css('left', left+"px");
								 
								 
		if(window.location.hash){
			var page = ""+window.location.hash.split("#")[1];	
			var e = new Object();
					e.url = page
					e.title = removeUnderscore(window.location.hash.split("#")[1].split('.html')[0]);
					//loadPage(e);
		}
		
		
		
 (function($){
        $.fn.extend({
                center: function (options) {
                        var options =  $.extend({transition:300, minX:0, minY:0}, options);
                        return this.each(function() {
                                $(this).css('position', 'absolute');
                                var top = ($(window).height() - $(this).outerHeight())/2+$(window).scrollTop();
                                var left = ($(window).width() - $(this).outerWidth())/2+$(window).scrollLeft();
                                $(this).css('top', top+"px");
                                 $(this).css('left', left+"px");
                                return $(this);
                        });
                }
        });
})(jQuery);



	$("#contactSubmit").live('click', function(){
			// validate($("#email").value())
			val = $("#email").val();
			var validatedEmail = validate(val);
			
			if(validatedEmail){
				alert("sending");
				$.post("_com/contactJSON.php", { 
					   email: $("#email").val(),
					    name:$("#name").val(),
						 topic:$("#topic").val(),
						  subject:$("#subject").val(),
						   message: $("#message").val()
					   
					   },
		
					function(data){
						 alert("Message Sent :" + data.response);
					}, "json"); 
				
			}
			
			 return false;						   
		});
	
   $('a[rel="internal"]').click(function(index) {
		//var href = $(this).attr('href').split(".php")[0];
		
    	// $(this).attr("id",  href );
		metricsClick($(this).text());
		 
  });
   
  $('a[rel="internal"]').live('click',function(){
				 
					// var currUrl = $(this).attr('href');
					// window.location.hash = currUrl; 
					//  page =  window.location.hash;
					 
					// if(curSubSec){
					//	   if($.browser.msie /*&& Number(jQuery.browser.version.split(".")[0]) < 7*/){
					/*		  
							 window.location.hash = curSec +"/"+ currUrl.split(docRoot)[1]; 
							page =  window.location.hash;
							

						   }else{
							 window.location.hash = curSec +"/"+ currUrl; 
							page =  window.location.hash;
							
						   }
					 }
					 
					 */
					// return false;
			 
		});
  $('a[rel="gui"]').click(function(){
		
		switch($(this).attr("id")){
			
			case "closePopUp":
			closeContentPopUp();
			break;
			
			case "recordNow":
			closeContentPopUp();
			break;
			
			case "closeMyAlert":
			myAlert(0,0 ,0 ,0);	
			break;
			
			
		}
		return false;
	
	});
   
  $('a[rel="internal"]').click(function(){
				 
				 
				 if(recordingSessionInProgress == true){
				
					/*
					 var currUrl = $(this).attr('href');
					  var hash = currUrl.split("")[1];
					 window.location.hash = hash;
					  page =  window.location.hash;
					
					// if(curSubSec){
					//	   if($.browser.msie ){
					 
					// document.getElementById('flashapp').changePage(currUrl);
					
					
					 var e = new Object();
					e.url = currUrl
					e.title = removeUnderscore($(this).text());
					loadPage(e);
					 
					 return false;*/
				 }
			 
			});
  

/**************************************** WINDOW  ****************************************/

   
	function winResize(){
	 left = $(window).width() /  2;
		 left = left - $("#diagram").width() / 2
		 $("#diagram").css('margin-left',left )
		
		 $("#popUpContent").css('position', 'absolute'); 
                                var left = ($(window).width() - $("#popUpContent").outerWidth())/2+$(window).scrollLeft();
                             
                                 $("#popUpContent").css('left', left+"px");
		 
			var width = $(window).width();
			//alert("width : " + width);
		width = width - ($("#logoTop").width() + $("#topRght").width());
			//alert("width : " + width);
		
		
		
		 if($.browser.msie){
		 		//$("#blackout").center()
			  $("#myAlertDiv").center();
 				$("#finishBtnImg").css("margin-left", "-200px"); 
			   
			   var contentleft = ($(window).width() - $("#content").outerWidth())/2+$(window).scrollLeft();
                            // $("#content").css('position', 'absolute');
                                 $("#content").css('margin-left', contentleft+"px");
				var finishPlcHldrleft = ($(window).width() - $("#finishPlcHldr").outerWidth())/2+$(window).scrollLeft();
                            // $("#content").css('position', 'absolute');
                                 $("#finishPlcHldr").css('margin-left', finishPlcHldrleft+"px");
								 
		   if($(window).width() <= 1300){
				//$("#topMid").css('width', width + "px"); 		
			$("#content").css('margin-left', "60px"); 
			$("#finishPlcHldr").css('margin-left', "610px"); 
				}  
			
		 }else{
			if(width > 520){
			//$("#topMid").css('width', width + "px");
			}else{
				//	$("#topMid").css('width', "520px");
			} 
			 
		 
		 }
		
	
		//alert(document.body.clientHeight);
		var x = $("#finishPlcHldr").offset().left - 93;	
		var y = $("#finishPlcHldr").offset().top;
		
		var ie6Val = document.getElementById("finishPlcHldr").offsetLeft + $("#finishPlcHldr").offsetParent().offset().left;// + document.getElementById("finishPlcHldr").offsetParent.offsetLeft;//
		
		
		var topPs =  y;
		//alert(y);
		
		
		if($.browser.msie /*&& Number(jQuery.browser.version.split(".")[0]) < 7*/){
			 var leftps =  (ie6Val + 140) + 'px' ;
				topPs = topPs + 20;
				
		}else if($.browser.safari){
		 var leftps = (x - 90) + 'px' ; 
			 
			 
		 }else{
			 var leftps = x + 'px' ; 
		 }
		   
		 topPs = topPs + "px";
			 $("#finishBtnImg").css("left", String(leftps));
		 	$("#finishBtnImg").css("top", String(topPs));
		 
				
				if(document.body.clientWidth < 900){
					   
				//	$('#shell').css('width', '900px'); 
					  
				}else{
					 $('#shell').css('width', '100%');   
					 
				}  
				
				  
				
				var linksLeft=	(document.body.clientWidth  * 1600) / 1920;
			 
			if(document.body.clientWidth > 1300){
				$("#right").css('padding-left', linksLeft+"px");
			}else{
				$("#right").css('padding-left', "1100px");
			}
			
			var navLeft = $("#mainnav").offset().left + popUpBorder;
$("#popUpContent").css("left", navLeft); 
					
					 
	}

	 $(window).bind('resize', function() {
			winResize();
					
		});
 
 

	
		
		
		var animCount = 1;
		

 
   $("#diagram").everyTime(10000,function(i) {
		
					   
				animCount++
			 if(animCount % 2){
				 
			 	

				$(this).animate({backgroundPosition: '0px -130px'}, 1500);
			 }else{
				$(this).animate({backgroundPosition: '0px 20px'}, 1500); 
			 }
					 
				  });
winResize();


		 
	 if($.browser.msie /*&& Number(jQuery.browser.version.split(".")[0]) < 7*/){
 /*
	$("#flashapp").css("margin-top", "0px"); 
	$("#mainnav").css("width", "271px"); 
	$("#leftContent").css("width", "271px");  
	*/ 
  }else{
	 
	 
  }
	 			

	
var x = $("#finishPlcHldr").offset().left - 93;	
		var y = $("#finishPlcHldr").offset().top;
		
		var ie6Val = document.getElementById("finishPlcHldr").offsetLeft + $("#finishPlcHldr").offsetParent().offset().left;// + document.getElementById("finishPlcHldr").offsetParent.offsetLeft;//
		var topPs =  y + 'px' ;
		
		
		//alert(y);
		
		
		if($.browser.msie /*&& Number(jQuery.browser.version.split(".")[0]) < 7*/){
			 var leftps =  (ie6Val + 40) + 'px' ;
				topPs = topPs + 20;
		}else if($.browser.safari){
			 var leftps = (x - 90) + 'px' ;  
			 
			 
		 }else{
			 var leftps = x + 'px' ; 
		 }
		 
		 topPs =  topPs + 'px' ;
				 
			 $("#finishBtnImg").css("left", String(leftps));
		 	$("#finishBtnImg").css("top", String(topPs));
		 
		 
	if($.browser.msie && Number(jQuery.browser.version.split(".")[0]) < 7){
	
		$("#blackout").css("position", "absolute");
			 
		
	}
	
	$(window).scroll(function() {
		  if($.browser.msie){
			 // $("#blackout").center()
			 // $("#myAlertDiv").center();
			 
		  }
	});					
	 
	
	// 
//myAlert(1, "asdfas", "adsffffffffffff asdffffffffff asdflh asd d;ohsad;oh shasd lhfds  ;uhsd;h ;h dsaf", 1); 
var navLeft = $("#mainnav").offset().left + popUpBorder;
$("#popUpContent").css("left", navLeft); 
//alert(navLeft);
 	
if($.browser.safari){
	$("#finishBtnImg").css("margin-left", "100px");
}

 

if(help){
	
$(".answer").slideUp("slow");
$('.question').css('cursor', 'pointer');
$(".question").click(function(){
	var next = $(this).next()
	$(".answer").each(function() {
							   
if($(this) != next){
           $(this).slideUp("fast");
		   }
		   
		   });
							  
	$(this).next().slideDown("slow");  
});
	
}

function metricsClick(e){
	//alert(e);
	
	$.post("_com/metrics/metrics.php", { 
					   clickedname:e
					   
					   },
		
					function(data){
						 alert("metrics update");
					}, "json"); 
}


});	


	/**************************************** UTILITY  ****************************************/ 	 

 function loadPage(e){ 

 $("#popUpContent div.content").load(e.url);
 $("#popUpContent").css("visibility", "visible");
  $("#popUpContent").css("display", "block");
 $(".popUpTitle").text(e.title);
 
  $("#popUpContent").slideDown("slow");

	 /*	$.ajax({
				url: "about_baktrack.php" ,
				cache: false,
				success: function(html){
					$("#popUpContent.content").text(html);
					$("#popUpContent").css("visibility", "visible");
				}
		}); */
 }
 
 function closeContentPopUp(){
	$("#popUpContent").css("visibility", "hidden"); 
 }
	 
	/**************************************** DEEP LINKING  ****************************************/
 

function validate (value) {
				regex=/^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
				return regex.test(value);
}
  
  
function playVideo (value) {
		document.getElementById("flashapp").playVideo();
}
  

	/**************************************** METRICS  ****************************************/
 


