$(document).ready(function(){

 Cufon.replace('#nav li a', {hover: true, textShadow: '2px 1px rgba(0, 0, 0, 0.3)'});
 Cufon.replace('.georgia', {hover: true});

 Shadowbox.init({handleOversize: "drag"});

// Center Navigation
 var menuWidth = $("#nav").width();
 var diff = 958 - menuWidth;
 var divide = diff / 3;
 //$("#nav li:first").css("margin-left", divide+"px");

 $('.feed:last').css('border-right','0px');
 $('.newsItem:first').css('border-top','1px solid #E5E5E4');
 $('.featureClient:first').css('margin-top','1px');
 $('.featurebox:first').css('margin-top','0px');

 var rightContainer = $('#holder').find('#rightpanel');
 if(rightContainer == true){
  $('#insidemiddle').css('width','720px');
 }

 /* ------------------------------- */
// Equal Heights
/* ------------------------------- */
function equalHeight(group) {
    tallest = 0;
    group.each(function() {
       thisHeight = $(this).height();
       if(thisHeight > tallest) {
        tallest = thisHeight;
      }
    });
    group.height(tallest);
}

equalHeight($(".col"));
equalHeight($(".feed h3"));
equalHeight($(".feedtext"));

 var equalBoxes = $('#listholder').height();
 var balanceIT = equalBoxes - 1;
 $('#seminartxtHolder').css('height',balanceIT+'px');

/*-------------------------------------- */
/* Navigation
/*-------------------------------------- */

	$("ul.subnav").parent().append("<span></span>"); //Only shows drop down trigger when js is enabled (Adds empty span tag after ul.subnav*)

	$("ul#nav li a").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
    $(this).addClass('dropdownarrow');
    
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			$(this).parent().find('a').removeClass('dropdownarrow');
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

	$("ul#secondnav li a").hover(function() { //When trigger is clicked...

		//Following events are applied to the subnav itself (moving subnav up and down)
		$(this).parent().find("ul.subnav").slideDown('fast').show(); //Drop down the subnav on click
    $(this).addClass('dropdownarrow');
    
		$(this).parent().hover(function() {
		}, function(){
			$(this).parent().find("ul.subnav").slideUp('slow'); //When the mouse hovers out of the subnav, move it back up
			$(this).parent().find('a').removeClass('dropdownarrow');
		});

		//Following events are applied to the trigger (Hover events for the trigger)
		}).hover(function() {
			$(this).addClass("subhover"); //On hover over, add class "subhover"
		}, function(){	//On Hover Out
			$(this).removeClass("subhover"); //On hover out, remove class "subhover"
	});

/*-------------------------------------- */
/* Extend News
/*-------------------------------------- */
   
    var findItems = $('#leftpanel').find('seminar');
    if(findItems != true){
     $('#latestnews').css('width','599px');
     $('#latestnews h2').css('width','599px');
     $('#latestnews #listholder').css('width','603px');
     $('#latestnews .newsItem').css('width','589px');
    }
    


/*-------------------------------------- */
/* Poll
/*-------------------------------------- */
//$("#submitanswer").attr("disabled", "disabled").fadeTo('slow', 0.5);
//$("#submitanswer").fadeTo('slow', 0.5);

$(".answers").click(function() {
 $('#udetails').slideDown('slow');
});

/*$("#newsletterYes").click(function() {
 
 if ( this.checked )
 {
 $('#udetails').slideDown('slow');
 }
 else
 {
 $('#udetails').slideUp('slow');
 }
}); */

$("#pollfrm").submit(function() {

  //if ( !$("#newsletterYes").attr("checked") ) return true;
  
   var msg = "Please enter the following fields:\n\n";
  
  var err = false;
  
  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  
  var poll_id = $("input[name='poll_id']").val();
  
     $("input[name='poll"+poll_id+"']").each(function () {
        if ( !$(this).attr("checked") )
        {
          err = true;
          
                      
        }
        else
        {
        
         err = false;
         
         return false;        
        }
              
      });
      
     
  if ( err )
  {
  
    msg += "Choose an option\n";
  
  }
  
  if ( $("#newsletterYes").attr("checked") )
  { 
   if ($("input[name='name']").val() == '' )
   {
    err = true;
    
    msg += "Name\n";
   }
   
   
   if ($("input[name='email']").val() == '' )
   {
    err = true;
    
    msg += "Email\n";
   }
   else if(!emailReg.test($("input[name='email']").val())) 
   {
      err = true;
      
      msg += "Valid Email\n";
   }
  } 
   
    if (err)
    {
     alert( msg );
     return false;
    }
    
    return true; 
      
    });

/*$("#name").blur(function() {
  var check1 = $("#name").val();
  var check2 = $("#miytyi-miytyi").val();
  if (check1 == '') {var check1empty = 1; $("#fullname").addClass('error');} else {var check1empty = 0;}
  if (check2 == '') {var check2empty = 1; $("#email").addClass('error');} else {var check2empty = 0;}

  if(check1empty == 0 && check2empty == 0) {
   $("#submitanswer").removeAttr("disabled").fadeTo('slow', 1.0);
  }

});

$("#miytyi-miytyi").blur(function() {
  var check1 = $("#name").val();
  var check2 = $("#miytyi-miytyi").val();
  if (check1 == '') {var check1empty = 1; $("#fullname").addClass('error');} else {var check1empty = 0;}
  if (check2 == '') {var check2empty = 1; $("#email").addClass('error');} else {var check2empty = 0;}

  if(check1empty == 0 && check2empty == 0) {
   $("#submitanswer").removeAttr("disabled").fadeTo('slow', 1.0);
  }

}); */


// Poll Results
 $('.smoothslide').animate({
  'width': '-=154px'
 },8000);
 
 //response mechanism
 $("#request_email_link").click(function() {
 $('#responsefrm').slideDown('slow');
  $('#comments_box').slideUp('fast');
  $('#sendfriendfrm').slideUp('fast');
});

$("#frm").submit(function() {
  var msg = "Please enter the following fields:\n\n";
  
  var err = false;
  
  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  
   if ($("#response_fullname").val() == '' )
   {
    err = true;
    
    msg += "Name\n";
   }
   
   if ($("#response_phone").val() == '' )
   {
    err = true;
    
    msg += "Phone\n";
   }
   
   if ($("#response_email").val() == '' )
   {
    err = true;
    
    msg += "Email\n";
   }
   else if(!emailReg.test($("#response_email").val())) 
   {
      err = true;
      
      msg += "Valid Email\n";
   }
   
    if (err)
    {
     alert( msg );
     return false;
    }
    
    return true; 
      
    });
    
    
  //send to a friend  
  $("#send_friend_link").click(function() {
  $('#sendfriendfrm').slideDown('slow');
  $('#comments_box').slideUp('fast');
 $('#responsefrm').slideUp('fast');
});

$("#friendfrm").submit(function() {
  var msg = "Please enter the following fields:\n\n";
  
  var err = false;
  
  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  
   if ($("input[name='yourname']").val() == '' )
   {
    err = true;
    
    msg += "Your Name\n";
   }
   
   if ($("input[name='friendname']").val() == '' )
   {
    err = true;
    
    msg += "Friend's Name\n";
   }
   
   if ($("input[name='friendemail']").val() == '' )
   {
    err = true;
    
    msg += "Friend's Email\n";
   }
   else if(!emailReg.test($("input[name='friendemail']").val())) 
   {
      err = true;
      
      msg += "Valid Friend's Email\n";
   }
   
    if (err)
    {
     alert( msg );
     return false;
    }
    
    return true; 
      
    });
    
    //seminar  
  $("#seminar_reg_link").click(function() {
 $('#seminardiv').slideDown('slow');
});

$("#seminarfrm").submit(function() {
  var msg = "Please enter the following fields:\n\n";
  
  var err = false;
  
  var emailRegPat = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  
   if ($("input[name='name']").val() == '' )
   {
    err = true;
    
    msg += "Your Name\n";
   }
   
   if ($("input[name='phone']").val() == '' )
   {
    err = true;
    
    msg += "Phone\n";
   }
   
   if ($("input[name='email']").val() == '' )
   {
    err = true;
    
    msg += "Email\n";
   }
   else if(!emailRegPat.test($("input[name='email']").val())) 
   {
   
     err = true;
      
      msg += "Valid Email\n";
   }
   
   if ($("input[name='company']").val() == '' )
   {
    err = true;
    
    msg += "Company\n";
   }
   
    if (err)
    {
     alert( msg );
     return false;
    }
    
    //serialize the form
    var frm = $("#seminarfrm").serialize();
    
    window.open(baseURL+'processpayment?process=Y&'+frm,'Process','height=600,width=800,status=yes,toolbar=no,menubar=no,location=no');
    
    return false;
      
    });
    
      //blog  
  $("#blog_link").click(function() {
 $('#comments_box').slideDown('slow');
 $('#responsefrm').slideUp('fast');
 $('#sendfriendfrm').slideUp('fast');
});

$("#blogfrm").submit(function() {
  var msg = "Please enter the following fields:\n\n";
  
  var err = false;
  
  var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
  
   if ($("#blog_fullname").val() == '' )
   {
    err = true;
    
    msg += "Name\n";
   }
   
      
   if ($("#blog_email").val() == '' )
   {
    err = true;
    
    msg += "Email\n";
   }
   else if(!emailReg.test($("#blog_email").val())) 
   {
      err = true;
      
      msg += "Valid Email\n";
   }
   
   if ($("#blog_comments").val() == '' )
   {
    err = true;
    
    msg += "Comments\n";
   }
   
    if (err)
    {
     alert( msg );
     return false;
    }
    
    return true; 
      
    });
   
});

