$(document).ready(function(){
	
	if ($("#perspective a.video_tb").length) {
		$("#perspective a.video_tb").click(function(){
			var mediaUrl = $("#perspective a.video_tb").attr('href');
	    // if cloud front url then modify
		  var vidSplit = mediaUrl.split("cfx");
		  if(vidSplit.length > 1){
		    mediaUrl = mediaUrl.replace("http","rtmp");
		    mediaUrl = mediaUrl + "&cf=true&";
		  } 
		  tb_show('','/homevideo20111230/?flv='+mediaUrl+'&height=300&width=490');
		  // tb_show('','/page/1/home-video-player.jsp?flv='+mediaUrl+'&height=300&width=490');
		  // tb_show('','/homevideo20111229/?flv='+mediaUrl+'&height=300&width=490');
		  // ?flv=http://sdib7r2t5qyil.cloudfront.net/cfx/st/two_minute_demo.mp4&cf=true&height=300&width=490
		  return false;
		});
	}	
	
	/* For Tuesday! */
	$("#home #TB_closeWindowButton,#home #TB_overlay").live('click',function(){
		window.location = "/page/1/pricing-options.jsp";
	});
	
	
	// style update for user resizing of text issue: 
	// http://valtira.zendesk.com/tickets/600?col=0
	$(".calledAction img").removeAttr("height").removeAttr("width").attr("width","540").attr("height","133");
  
  // validates login form including phone number
	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 */
	
	$("#loginForm").validate({
	  rules: { /* rules adding for validator */
	    phone: {
	      required: true,
	      phoneUS: false
	    }
		}
	});
	
	// jQuery overlay & expose used for modal window 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
	});

    
	$(".iewrap").hover(hoverOver,hoverOut);
	
	function hoverOver(){
	
	if ($(this).is('.iewrap.lover') || ($.browser.msie && $.browser.version == '8.0') ) {
	//this has the class (do absolutely nothing)
	
	} 
	else {
	//this doesn't have the class
	$(this).siblings('.iewrap').stop(true,false).fadeTo(50, .5);
	}

	}
	
	function hoverOut(){
	
	if ($(this).is('.iewrap.lover') || ($.browser.msie && $.browser.version == '8.0') ) {
	// this has the class (do absolutely nothing and wait)
	
	} 
	else {
	// this doesn't have the class
	$(this).siblings('.iewrap').stop(true,true).fadeTo(500, 1);
	}
	
	}
	

  var boxClick = {};

  function clickBox(el) { // what is this for?
    var thisElement = el;
  }

  $(".iewrap").click(function() {
   	
   	/* When adding the home page video popup functionality using ThickBox, 'easeInOutExpo' blows up. */
    if ($(this).is('.iewrap.lover')) { // this has the class (do absolutely nothing and wait)
		} 
		else { // this doesn't have the class lover (go forward my son...)    
    
    // name everything 
    boxClick.id = $(this).attr("id");
    thisBox = $("#"+boxClick.id);
    boxClick.left = $(thisBox).position().left;
    h2Box = $(thisBox).children(".box");
    smallBox = $(thisBox).children(".smallBox");
    infoExpander = $(thisBox).children(".infoExpander");
    
    // add class lover to all .iewraps to lock things down until expanded box is closed, etc. & hide the siblings
    $(thisBox).addClass("lover").siblings().addClass("lover");
    $(thisBox).siblings(".iewrap").hide();

		// hide the arrow after click, fade the smallbox out, move boxes to the left
		$(h2Box).children(".arrow:first").css("display","none");
		if ($.browser.msie && $.browser.version == '8.0') {
			$(smallBox).stop(true,true).animate({"left": "0px"}, "slow"/* , 'easeInOutExpo' */);
    $(thisBox).stop(true,true).animate({"left": "0px"}, "slow"/* , 'easeInOutExpo' */);
		} 
		else {
			$(smallBox).stop(true,true).animate({opacity: 0, "left": "0px"}, "slow"/* , 'easeInOutExpo' */);
    $(thisBox).stop(true,true).animate({opacity: 1, "left": "0px"}, "slow"/* , 'easeInOutExpo' */);
		}


    // slide the expanding box open (and contents) then show the close button 
    if ($.browser.msie && $.browser.version == '8.0') {
    	$(infoExpander).css({"margin-left":"0"}).stop(true,true).animate({width:"show"}, "slow"/* , 'easeInOutExpo' */);
    }
    else {
    	$(infoExpander).css({"margin-left":"0"}).stop(true,true).animate({width:"show", opacity: 1}, "slow"/* , 'easeInOutExpo' */);
    }
    
    // an attempt to deal with the opacity weirdness in IE     
    $(h2Box).css({"display":"inline","filter":"Alpha(Opacity=100)","background-color":"#dc291e"}).css("background-color","transparent");
    setTimeout(function(){
    	$(thisBox).siblings(".closeBox").css("display","block");
    }, 500);
    
    
	  // closes the expanded box, move it, & fade it out
	  $(".closeBox").click (function() {
			// hide the close button
			$(this).css("display","none");
			// fade in the small box, close the expanded box, and move the box back to its original place
			if ($.browser.msie && $.browser.version == '8.0') {
				$(smallBox).stop(true,false).show();
				$(infoExpander).stop(true,false).animate({width:"hide"}, "fast"/* , 'easeInOutExpo' */);
			}
			else {
				$(smallBox).stop(true,false).fadeTo("fast", 1.0);
				$(infoExpander).stop(true,false).animate({width:"hide",opacity: 0}, "fast"/* , 'easeInOutExpo' */);
			}
			         
			$(thisBox).stop(true,false).animate({"left": [ boxClick.left+"px" ]}, "slow"/* , 'easeInOutExpo' */);   	
			
			// wait a little while and fade in other squares, arrow, and remove the lover class so things are free to be clicked
			setTimeout(function(){
				if ($.browser.msie && $.browser.version == '8.0') {
					$(thisBox).siblings(".iewrap").stop(true,true).show();
				} 
				else {
					$(thisBox).siblings(".iewrap").stop(true,true).fadeTo(1500, 1.0);
				}

				$(h2Box).children(".arrow:first").css("display","inline");
				$(thisBox).removeClass("lover").siblings().removeClass("lover");
				// an attempt to deal with the opacity weirdness in IE 
				$(h2Box).css({"display":"inline","filter":"Alpha(Opacity=100)","background-color":"#dc291e"}).css({"background-color":"transparent"});
			// }, 750).delay(5000); // delay is not set right
			}, 750);
	  });
		
		} // added for my else!
	  
	});

  // the following is to switch the contents of the expanded box from the BIZ content to the TECH content; the next bit switches it back
  $(".infoDetail").tabs();

}); // end document.ready()
