/* jQuery tabs
/*-------------------------------------------------------------------------------*/

// product page tabs - custom configuration for external links to internal tabs
$(function() {
	// Initialize Tabs
	$('#tabContainer').tabs();
	
	if(document.location.hash!='') {
        //get the index from URL hash
      	tabSelect = document.location.hash.substr(1,document.location.hash.length);
		$("#tabContainer").tabs('select',tabSelect-1);
	}
});

// history page tabs - custom configuration for pagination scheme
$(function() {

	var $pagTabs = $('#modHistory').pagTabs();

	$(".ui-tabs-panel").each(function(i){

	  var totalSize = $(".ui-tabs-panel").size() - 1;

	  if (i != totalSize) {
	      next = i + 2;
   		  $(this).append("<a href='#' class='next-tab mover' rel='" + next + "'>Next Page &#187;</a>");
	  }

	  if (i != 0) {
	      prev = i;
   		  $(this).append("<a href='#' class='prev-tab mover' rel='" + prev + "'>&#171; Prev Page</a>");
	  }

	});

	$('.next-tab, .prev-tab').click(function() {
           $pagTabs.pagTabs('select', $(this).attr("rel"));
           return false;
       });
});


/* jQuery form validation
/*-------------------------------------------------------------------------------*/

$(document).ready(function() {
	$("#contactForm").validate();
});

$(document).ready(function() {
	$("#checkoutForm").validate();
});


/* new window _ rel=external
/*-------------------------------------------------------------------------------*/

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;