$(document).ready(function(){

	// call tabs when bizTechTabs class is present
	
  if($('.bizTechTabs').length >= 1 || $('.contactStartTabs').length >= 1) {
	  
	  $("#callout").tabs();
		
		// update contact us footer - depending upon tab you are on
		
		$("#contactTab").click(function() {
			$("#contact_footer").html("<p>*Required Fields</p>");
		});
		
		$("#startTab").click(function() {
			$("#contact_footer").html("<p>&nbsp;</p>");
		});
			  
	}
	
	
	if($.browser.msie && $.browser.version=="6.0") {
	
		// Need to adjust to measure the tabs - and subtract the closed/hidden one from the page. (on open, the tech tab)
		
		// scripting to auto-detect the footer padding-bottom and parse it w/o px 
	  
	  // $("div#content").css("padding-bottom", pb+'px' );
		
		popIt();
		
		$("ul.ui-tabs-nav li a").click(popIt);
		
		function popIt(){
		 
		 	var pb = parseInt($("div#content").css("padding-bottom"));
		 	
	    // was height auto, but testing this out as a reset
	    // $("div#content").height('auto !important');
			
			$("div#content").css({"height":"auto"});
			
	    setTimeout(function() { 
	    // now do the math to solidly set heights for content
	    var fh = $(document).height();
	    var hsub = fh - pb;  /* pb (429) is the current content padding-bottom used to keep footer down. */
	    $("div#content").attr("rel", pb); /* just a test to check parseInt(); */
			// $("div#content").height(hsub+'px');
			$("div#content").css("height",hsub+"px");
			
			// testing to see if reinforcing this helps keep that pesky footer down there.
			// $("footer").css("bottom","0");
			// $("footer").css("position","absolute");
			}, 500); 
			
	  }
	  
	}
	
  // video popup calls
  $('.video a').click(function(){
    var vidUrl = $(this).attr('href');
    // if cloud front url then modify
    var vidSplit = vidUrl.split("cfx");
    if(vidSplit.length > 1){
      vidUrl = vidUrl.replace("http","rtmp");
      vidUrl = vidUrl + "&cf=true&";
    }
    tb_show('','/page/1/new-video-player.jsp?flv='+vidUrl+'&height=300&width=490');
    return false;
  });

	$(".overlayLink a").attr('rel',"#video_modal");
	
	
  // video embed calls

  // use the jquery.flash 200003 to embed flash, content embedded via client
  $('span.videoembed').each(function(){
   		
   		
   		$(this).html('<div class="alt">'+$(this).html()+'</div>').addClass('flash-replaced');
   		$(this).after('<div id="noFlash">Hi.  <a href="http://www.adobe.com/go/getflashplayer/">You need Flash.</a></div>');
   		
	    var vidUrl = $(this).find('a').attr('href');
	    // if cloud front url then modify
	    var vidSplit = vidUrl.split("cfx");
	    if(vidSplit.length > 1){
	      vidUrl = vidUrl.replace("http","rtmp"); // Simplicis doesn't know what rtmp is?
	    }

      var params = {allowFullScreen: "true"};
      var flvPath = vidUrl;
      var pathSplit = flvPath.split("st/");
      var filename = pathSplit[1];
      var streamer = pathSplit[0]+"st/";
	    
	    swfobject.embedSWF("/media/flash/1/player.swf", "noFlash", "480", "290", "8", "http://verisae.com/media/flash/1/expressinstall.swf", {file:filename,streamer:streamer}, params);
	    
	    /* $(this).flash({
	        src: "/media/flash/1/player.swf",
	        width: 490,
	        height: 300,
	        flashvars: { file: vidUrl }
	      }); */

    // hide the orginal link which has been moved into div.alt (does this happen in flash?)
    $(this).find('.alt').hide();
  });
	
	
	jQuery.validator.addMethod("phoneUS", function(phone_number, element) { /* adds method phone number validation */
	  phone_number = phone_number.replace(/\s+/g, ""); 
		return this.optional(element) || phone_number.length > 9 &&
			phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
	}, "Please specify a valid phone number."); /* can also override in title of required inputs */
	    
	$("#startForm").validate({
	  rules: { /* rules adding for validator */
	    phone: {
	      required: true,
	      phoneUS: false
	    }
		}
	});
	
	$("#contactForm").validate({
	  rules: { /* rules adding for validator */
	    phone: {
	      required: true,
	      phoneUS: false
	    }
		}
	});
	
	$("#loginForm").validate({
	  rules: { /* rules adding for validator */
	    phone: {
	      required: true,
	      phoneUS: false
	    }
		}
	});
	
	$(".login a[rel]").overlay({
	
		left: 'center',
		top: '20%',
		// effect: 'apple',
	
	
	// some expose tweaks suitable for modal dialogs
	expose: {
		color: '#261006',
		loadSpeed: 200,
		opacity: 0.95
	},
	
	closeOnClick: true
	
	});


	$(".pop a[rel]").overlay({
		
		left: 'center',
		top: '10%',
		// effect: 'apple',
	
	
	// some expose tweaks suitable for modal dialogs
	expose: {
		color: '#261006',
		loadSpeed: 200,
		opacity: 0.95
	},
	
	closeOnClick: true,	

	onBeforeLoad: function() {
	
		var dh = $(document).height();
		
		$('div.sheldon_love').each(function(idx,el){
	    el.style.height = dh+'px';
	    
	  });
		
	}
	
	
	});
	
	$(".overlayLink a").attr('rel',"#video_modal");
	
	// video overlay link
	$(".overlayLink a[rel]").overlay({
		left: 'center',
		top: '20%',
		// effect: 'apple',
	
	
	// some expose tweaks suitable for modal dialogs
	expose: {
		color: '#261006',
		loadSpeed: 200,
		opacity: 0.95
	},
	
	closeOnClick: true,
	onBeforeLoad: function() { 
 
            // grab wrapper element inside content 
            var wrap = this.getContent().find(".contentWrap"); 
 
            // load the page specified in the trigger 
            wrap.load(this.getTrigger().attr("href")); 
        } 	
    });
  
  	/***********************************************
	*  Pricing plan page
	*  toggle expand/collapse link and tooltip
	************************************************/
	
	var toggleLink = $("div#planWrapper a.toggle");
  var origText = toggleLink.text();	
	toggleLink.click(function() {
    var detail = $("div#planWrapper div#detailTable");
    
    if ( detail.is(":hidden") ) {
      detail.show("fast");
      $(this).addClass("expanded");
      $(this).text("Hide pricing plan details");
    } else {
      detail.hide("fast");
      $(this).removeClass("expanded");
      $(this).text(origText);
    }
    return false;
	});

	$("div#planWrapper u").tooltip({ 
   //position: 'bottom center', // set default: under trigger element
   relative: true             // tooltip position relative to trigger element
  });//.dynamic();               // tooltip flips to top of not enough room to display - didn't behave nicely by side of page
  
  /* end pricing plan page scripts*/
  
});