
$(document).ready(function() {

  $('input[type="text"]').addClass('placeholder').focus(function() {
    var initialValue = $(this).val();
    var startVal = $(this).attr( 'startVal' );
    var placeholderText = $(this).attr('title');
    
    //if current text field value = placeholder text (title value, in this case)
    //make blank else, 
    //remove placeholder class & do not clear text field  upon click
    if($.trim($(this).val()) == placeholderText){
  	  $(this).val('');    	
    }else{
  	  $(this).removeClass('placeholder');
    };
    
  }).blur(function() {
    //if the field is empty or value equals placeholder text, add placeholder class
    var val = $.trim($(this).val());
    if (val.length == 0 || val == $(this).attr('title')) {
      $(this).addClass('placeholder').val($(this).attr('title'));
    };
  });
  
  //on change, if placeholder class is assigned, remove it
  //add .blackText to alter text color
  $('input[type="text"]').change(function(){
  	if($(this).hasClass('placeholder')){
  		$(this).removeClass('placeholder');
  	}
	  	$(this).addClass('blackText');
  });
  
  //business rule: qryId should not be submitted with placeholder text or empty string  
  $("#twoBoxSearch").submit(function() {    	
  	if ($("#qryId").val()== $("#qryId").attr('title')) {
        $("#qryId").val('');      
        var the_result=checkQuestionMandatory(true);
        return the_result;          
      }else if($("#qryId").val()== ""){
      	var the_result=checkQuestionMandatory(true);
          return the_result;
      }else{
    	if($("#pnameId").val() == $("#pnameId").attr('title')){    	 
    	  $("#pnameId").val('');  	
    	}
      	return true;
      }  	
    }); 
  
  // overlay setup	    
  $('a[rel]').overlay({
  	top: 50,	    	
  	mask: { color: '#000000', loadSpeed: 200, opacity: 0.5 },
  	closeOnClick: false, 
  	onLoad: function() { 
  		this.getOverlay().insertAfter('#exposeMask');
  	}
  });
  
  $('div[rel]').overlay({
  	top: 50,	    	
  	mask: { color: '#000000', loadSpeed: 200, opacity: 0.5 },
  	closeOnClick: false, 
  	onLoad: function() { this.getOverlay().insertAfter('#exposeMask'); }
  });
  
  $('span[rel]').overlay();
  $('img[rel]').overlay();  
  
  //tooltip setup
  $(".hoverOverlayButton").tooltip({  	
  	position: 'top center',  	
  	relative:'true',	
  	effect: 'slide'  		
  });
  
  //special case: needed to prevent tooltip from covering 'next' button on softwareCat page CR2732
  $(".hoverOverlayButtonBelow").tooltip({	  	
    position: 'bottom center',	  	
	relative:'true',
	effect: 'slide'	  		
  });
 
  //geoLocator
  $("#clcHdrContent").overlay({	    	
  	top: 50,	    	
  	mask: {	    		
  		color: '#000000',	    		
  		loadSpeed: 200,	    		
  		opacity: 0.5
  	},	    	
  	closeOnClick: false,
  	onLoad:  function() { this.getOverlay().insertAfter('#exposeMask'); },
  	load: true    	
  });	    
  
  //harrisSurvey
  $("#harrisContent").overlay({	    	
  	top: 25,	    	
  	mask: {	    
  		color: '#000000',
  		loadSpeed: 200,
  		opacity: 0.5
  	},
  	closeOnClick: false,
  	//fixes IE7 z-index bug
  	onLoad:  function() {
  	      this.getOverlay().insertAfter('#exposeMask');},
  	load: true

  });   
  
//generic non-autoload overlay 
  $(".jqOverlayTreatment").overlay({	    	
  	top: 25,	    	
  	mask: {	    
  		color: '#000000',
  		loadSpeed: 200,
  		opacity: 0.5
  	},
  	closeOnClick: false,
  	//fixes IE7 z-index bug
  	onLoad:  function() {
  	      this.getOverlay().insertAfter('#exposeMask');}
  
  });
  
  //media order error overlay  non-autoload and NOT modal. User needs access to text fields on the page.
  $(".businessError").overlay({
    top: 25,
    api: true,
	mask: {	    
	  color: '#000000',
	  loadSpeed: 200,
	  opacity: 0.5
	 },
	 closeOnClick: true,
	 onLoad:  function() {
 	     this.getOverlay().focus();
 	     this.getOverlay().insertAfter('#exposeMask');
 	 }, 
 	 onClose: function(){ 		 
 		 moApp.errorList.reset()
 	 }
  });
  
  
  
  $('.jqOverlay .close').click( function(button) {
      button.preventDefault();
  });
  
  //controls sequence of events on weDispute form submit. Fixes IE issue.
  $("#disputeForm").submit(function() {	    	     
        var the_result=weDisputeWfv(this);
        if(the_result){
      	  $("#disputeContentId").overlay({
      		  load:true
      	  });
        }
        return the_result;
  	
    });
  
//*stalker survey functions
  
  //required to set CFR variables prior to survey submission 
  $('a#yesnoButton1').click(function(){
    survey_yes('yesnoContent1','yesnoButton1','yesnoClose1');
  });
  $('a#yesnoButton2').click(function(){
    survey_no('yesnoContent2','yesnoButton2','yesnoClose2');
  });
  $('a#yesnoButton3').click(function(){
    survey_browse('yesnoContent3','yesnoButton3','yesnoClose3');
  });  
  
  //close stalker survey following submission
  	if("#yesNoFloat"){
  		$('#submit_thankyou1').click(function() {
  			$('#yesNoFloat').hide();
  		});
  		$('#submit_thankyou2').click(function() {
  			$('#yesNoFloat').hide();
  		});
  		$('#submit_thankyou3').click(function() {
  			$('#yesNoFloat').hide();
  		});
  	}
  	
  //brightcove video -- stops playback when modal window is closed   
    var bcExp;
    var modVP;
    var modExp;
    var modCon;     
  
    function onTemplateLoaded(experienceID) 
    {
      alert('template loaded...');
      bcExp = brightcove.getExperience(experienceID);
      modVP = bcExp.getModule(APIModules.VIDEO_PLAYER);
      modExp = bcExp.getModule(APIModules.EXPERIENCE);
      modCon = bcExp.getModule(APIModules.CONTENT);
      $('#videoContent #videoClose').bind("click", function(){
        //modVP.pause(true);
        modVP.stop();
      });
    } 
   
  	
  $('.hidden').hide(); 

  $('.limited').each( function() {
    var limitedLimit = $(this).attr('limit') - 1;
    $(this).children('.wcLink:gt('+ limitedLimit +')').hide();
    $(this).children(':not(.wcLink):gt('+ limitedLimit +')').hide();
    // hide see more link if there are less links than the limit.
    var limitedLength = $(this).children().length;
    var limitedName = $(this).attr('name');
    if ( limitedLength <= limitedLimit ) {
       $('[linkFor='+limitedName+']').hide();
    }
  });

  // find the show more element for a limited and make it handle clicks.
  $('[linkFor='+$('.limited').attr('name')+']').click( function() {
    var linkForName = $(this).attr('linkFor');
    $('.limited[name='+linkForName+']').children().slideDown( 'slow', function(){} );
    // hide show more link
    $(this).hide();
  });

  if ($('input').is('.privacy_validate')) {
    $('#privacyDocPopup').hide();
  
    $('#continue').click( function(e) {
      var p1 = $('input[name="privacy_1_opt"]:radio:checked').addClass('checked').val();
      var p2 = $('input[name="privacy_2_opt"]:radio:checked').addClass('checked').val();
      var p3 = $('input[name="privacy_3_opt"]:radio:checked').addClass('checked').val();
      var result = false;
  
      if (p1 == "yes" && p2 == "yes" && p3 != undefined) {
         result = true;
      } else {
         $('#privacyDocPopup').slideDown('slow', function(){});
      }
      result=wfv(document.email) && result;
      return result;
  });
  
  } else {
    $('#continue').click( function() {
      return wfv(document.email); 
    });
  }
  
  // clickPost event
  $("a.clickPost").click( function() { $('#disputeEmailForm').submit(); return false; });

});




