
$(document).ready(function(){ 
						   
	extLinks();
	replaceHrTag();
	styleSecondCol();
	StripeTable();


   
   
	$(window).bind("load", function() { 				 
 		$('body .smallboxes .bottombox').equalHeights;		 
 		$('#footer .inner').equalHeights;
	}); 
	

	var userAgent = navigator.userAgent.toLowerCase();
	// Is this a version of Safari?
	if($.browser.safari){
		$('body').addClass('safari');
		// Add the version number
		userAgent = userAgent.substring(userAgent.indexOf('version/') +8);
		userAgent = userAgent.substring(0,1);
		//$('body').addClass('safari' + userAgent);
	}
	$('.terms').hide();
    $('.slideterms').click(function () {
      if ($(".terms").is(":hidden")) {
        $(".terms").slideDown("slow");
      } else {
        $(".terms").slideUp("slow");
      }
    });
	
	
	
	// Hover emulation for IE 6.
  if ($.browser.msie && parseInt(jQuery.browser.version) == 6) {
	  
   DD_belatedPNG.fix('#topimg');
   DD_belatedPNG.fix('.topsidepanel');
   
   //$('#topimg').css('margin-bottom','10px');

   $('#navigation-sub li').hover(function() {
      $(this).addClass('ieHover');
    }, function() {
      $(this).removeClass('ieHover');
    });
   
   $('#navigation li a').hover(function() {
      $(this).addClass('ieHover');
    }, function() {
      $(this).removeClass('ieHover');
    });
   
   
   $('#sidenavigation li').hover(function() {
      $(this).addClass('ieHover1');
    }, function() {
      $(this).removeClass('ieHover1');
    });
  }
  
  
  attachboxlinks();
  
  
   $(".gallery a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});
   
   $("a[rel^='prettyPhoto']").prettyPhoto({theme:'light_rounded'});
 
  
  

});

attachboxlinks = function(){
	
  	$(".smallboxes .middlebox").each(function(i){
    	var hrefArr = $(this).find('a').attr('href');
  
  		$(this).click(function(){
    		location.href = hrefArr;
  		});
  		$(this).css("cursor","pointer");
	});
	
  	$(".rightboxes .middlebox").each(function(i){
    	var hrefArr = $(this).find('a').attr('href');
  
        var isGallery = $(this).find('.gallery').is('.gallery');

  		$(this).click(function(){
    		if(isGallery){
    			$.prettyPhoto.open(hrefArr);
			}else{
    			location.href = hrefArr;
			}
  		});
  		$(this).css("cursor","pointer");
	});
	
  	$(".smallboxes .rightbox").each(function(i){
    	var hrefArr = $(this).find('a').attr('href');
  
  		$(this).click(function(){
    		location.href = hrefArr;
  		});
  		$(this).css("cursor","pointer");
	});

}

	
function extLinks(){
	$('a[rel*="external"]').click(function(){
		window.open(this.href);
		return false;
	});
	$('a[rel*="met"]').click(function(){
		window.open(this.href);
		return false;
	});
}

function replaceHrTag(){	
	$("hr").wrap("<div class='divider2'></div>");
}

function StripeTable(){	// must include table plugin to use this function			
	$(".leftcol tr").mouseover(function(){
		$(this).addClass("over");
	}).mouseout(function(){
		$(this).removeClass("over");
	});
	$(".leftcol tr:even").addClass("alt");  
}

function styleSecondCol(){
    $('tr').each(function(){		  
		var count=1;
    	$('td').each(function(){
      		count++;
			//alert(count);
			if(count%2 != 0){ 
				$(this).addClass("txtright");
			}
    	})
    })
}


function addPrintLink(){
	// add print page link - since it can only work for JS, only add it for JS users
	$('#print') // create list item
    .addClass('print') //add relevant class to it
    .append('<a href="javascript:window.print();">Print this page</a>') //put in the link
    .insertBefore('li a.foo'); //add before the li item with link of class 'foo'
}

