jQuery().ready(function(){
	jQuery('#accordion').accordion({
		header: '.acHead',
		navigation: true,
		event: 'mouseover',
		fillSpace: true,
		autoheight: true
	});
	$("#accordion ul").css({ height : "63px"});
});

$(document).ready(function(){

	/*var config = {    
     	sensitivity: 3, // number = sensitivity threshold (must be 1 or higher)    
	     interval: 200, // number = milliseconds for onMouseOver polling interval    
	     over: makeTall, // function = onMouseOver callback (REQUIRED)    
	     timeout: 500, // number = milliseconds delay before onMouseOut    
	     out: makeShort // function = onMouseOut callback (REQUIRED)    
	};

//$("#demo3 li").hoverIntent( config )*/


	//Add class to alternating rows
	$("#registrars table.roundBoxTable tr:nth-child(odd)").addClass("rowColor");
		
	//Filtering Controls & Hovers
	$("#f1").hoverIntent({
		sensitivity: 3, 
		interval: 200, 
		over: openf1, 
		timeout: 500, 
		out: closef
	});
		function openf1(){
			var pos = $("#f1").offset();
			var width = $("#f1").width();
			var fine = pos.top - -25;
			$("#f1-fly").css({ "left": (pos.left) + "px", "top":fine + "px"});
			$("#f1-fly").css({ display : "block"});
			$("#f1").css({ backgroundImage : "url(/images/naming/filter-bg-h.gif)"});
			
			//Close Other Boxes
			$("#f2").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
			$("#f2-fly").css({ display : "none"});
		
			$("#f3").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
			$("#f3-fly").css({ display : "none"});
		}

				 
		$("#f2").hoverIntent({
			sensitivity: 3, 
			interval: 200, 
			over: openf2, 
			timeout: 500, 
			out: closef
		});
		
		function openf2(){
			var pos = $("#f2").offset();
			var width = $("#f2").width();
			var fineT = pos.top - -26;
			var fineL = pos.left - 198;
			$("#f2-fly").css({ "left":fineL + "px", "top":fineT + "px"});
			$("#f2-fly").css({ display : "block"});
			$("#f2").css({ backgroundImage : "url(/images/naming/filter-bg-h.gif)"});
			
			//Close Other Boxes
			$("#f1").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
			$("#f1-fly").css({ display : "none"});
			
			$("#f3").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
			$("#f3-fly").css({ display : "none"});
			
			if (jQuery.browser.msie){
				if(parseInt(jQuery.browser.version) == 6){
					$("#f2-fly div ul").css({ display : "none"});
					$("#f2-fly div ul").css({ display : "block"});
				}
			}
		}


		$("#f3").hoverIntent({
			sensitivity: 3, 
			interval: 200, 
			over: openf3, 
			timeout: 500, 
			out: closef
		});
		
		function openf3(){
			var pos = $("#f3").offset();
			var width = $("#f3").width();
			var fineT = pos.top - -26;
			var fineL = pos.left - 396;
			$("#f3-fly").css({ "left":fineL + "px", "top":fineT + "px"});
			$("#f3-fly").css({ display : "block"});
			$("#f3").css({ backgroundImage : "url(/images/naming/filter-bg-h.gif)"});
			
			//Close Other Boxes
			$("#f1").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
			$("#f1-fly").css({ display : "none"});
			
			$("#f2").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
			$("#f2-fly").css({ display : "none"});
		}
		
		function closef(){}


	//Initial Pagination after page loads
	$('table.paginated').each(function() {
		var currentPage = 0;
		var numPerPage = 50;
		var $table = $(this);
	
		$table.bind('repaginate', function() {
			$table.find('tbody tr').show()
			.slice(0,currentPage * numPerPage)
			.hide()
			.end()
			.slice((currentPage + 1) * numPerPage)
			.hide()
		.end();
	});
	
	var numRows = $table.find('tbody tr').length;
	var numPages = Math.ceil(numRows / numPerPage);
	var $pager = $('<div class="pager"></div>');
	
	for (var page = 0; page < numPages; page++) {
		$('<span class="page-number">' + (page + 1) + '</span>')
		.bind('click', {'newPage': page}, function(event) {
		currentPage = event.data['newPage'];
		numPerPage = 50;
		$table.trigger('repaginate');
		$(this).addClass('active').siblings().removeClass('active');
	})
		.appendTo($pager).addClass('clickable');
	}
	$('<span class="view-all">View All</span>').bind('click', {'newPage':page}, function(event) {
		$(this).addClass('active').siblings().removeClass('active');
		currentPage = 0;
		numPerPage = numRows;
		$table.trigger('repaginate');
	}).appendTo($pager).addClass('clickable');
		$pager.find('span.page-number:first').addClass('active');
		$pager.insertAfter($table);
		$table.trigger('repaginate');
	});


	//-----------FUNCTIONS FOR FILTERING-----------
	//Search if Name is clicked
	$("#filter .filters #f1-fly div ul li a").click(function(){	
		//Close Other Boxes
		$("#f1").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f1-fly").css({ display : "none"});
		$("#f2").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f2-fly").css({ display : "none"});
		$("#f3").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f3-fly").css({ display : "none"});
		
		//Hide & Reset all rows
		$("#registrars table.roundBoxTable tr").hide();
		$("#registrars table.roundBoxTable tr").removeClass("rowColor");
		$("#registrars table.roundBoxTable tr").removeClass("results");
		
		//Get filter type
		var filter = $(this).html();
		
		//Filter Rows
		$("#registrars table.roundBoxTable tr td.name").each(function(){
			var filteredText = $(this).children("a").html().slice(0,1);
			if (filteredText == filter){
				$(this).parent().show();
				$(this).parent().addClass("results");
			}
		});
		
		//Apply Row Background Color to results
		$().find("#registrars table.roundBoxTable tr").not(":hidden").filter(":even").addClass("rowColor");
		
		//Re-Paginate Results
		$("div.pager").remove();
		$('table.paginated').each(function() {
			var currentPage = 0;
			var numPerPage = 50;
			var $table = $(this);
		
			$table.bind('repaginate', function() {
				$table.find('tbody tr.results').show()
				.slice(0,currentPage * numPerPage)
				.hide()
				.end()
				.slice((currentPage + 1) * numPerPage)
				.hide()
			.end();
		});
		
		var numRows = $table.find('tbody tr.results').length;
		var numPages = Math.ceil(numRows / numPerPage);
		var $pager = $('<div class="pager"></div>');
		
		for (var page = 0; page < numPages; page++) {
			$('<span class="page-number">' + (page + 1) + '</span>')
			.bind('click', {'newPage': page}, function(event) {
			currentPage = event.data['newPage'];
			numPerPage = 50;
			$table.trigger('repaginate');
			$(this).addClass('active').siblings().removeClass('active');
			$("#registrars table.roundBoxTable tr:not(.results)").css({ display: "none"});
		})
			.appendTo($pager).addClass('clickable');
		}
		$('<span class="view-all">View All</span>').bind('click', {'newPage':page}, function(event) {
			$(this).addClass('active').siblings().removeClass('active');
			currentPage = 0;
			numPerPage = numRows;
			$table.trigger('repaginate');
		}).appendTo($pager).addClass('clickable');
			$pager.find('span.page-number:first').addClass('active');
			$pager.insertAfter($table);
			$table.trigger('repaginate');
		});
		
		//Check for rows not in the results and fix for rows that still show
		$("#registrars table.roundBoxTable tr:not(.results)").css({ display: "none"});
	});

	//Search if Country is clicked
	$("#filter .filters #f2-fly div ul li a").click(function(){	
		//Close Other Boxes
		$("#f1").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f1-fly").css({ display : "none"});
		$("#f2").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f2-fly").css({ display : "none"});
		$("#f3").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f3-fly").css({ display : "none"});
		
		//Hide & Reset all rows
		$("#registrars table.roundBoxTable tr").hide();
		$("#registrars table.roundBoxTable tr").removeClass("rowColor");
		$("#registrars table.roundBoxTable tr").removeClass("results");
		
		//Get filter type
		var filter = $(this).html();
		
		//Filter Rows
		$("#registrars table.roundBoxTable tr td.ctry:contains('" + filter + "')").each(function(){
			$(this).parent().show();
			$("#registrars table.roundBoxTable tr").not(":hidden").addClass("results");
		});
		
		//Apply Row Background Color to results
		$().find("#registrars table.roundBoxTable tr").not(":hidden").filter(":even").addClass("rowColor");
		
		//Re-Paginate Results
		$("div.pager").remove();
		$('table.paginated').each(function() {
			var currentPage = 0;
			var numPerPage = 30;
			var $table = $(this);
		
			$table.bind('repaginate', function() {
				$table.find('tbody tr.results').show()
				.slice(0,currentPage * numPerPage)
				.hide()
				.end()
				.slice((currentPage + 1) * numPerPage)
				.hide()
			.end();
		});
		
		var numRows = $table.find('tbody tr.results').length;
		var numPages = Math.ceil(numRows / numPerPage);
		var $pager = $('<div class="pager"></div>');
		
		for (var page = 0; page < numPages; page++) {
			$('<span class="page-number">' + (page + 1) + '</span>')
			.bind('click', {'newPage': page}, function(event) {
			currentPage = event.data['newPage'];
			numPerPage = 50;
			$table.trigger('repaginate');
			$(this).addClass('active').siblings().removeClass('active');
			$("#registrars table.roundBoxTable tr:not(.results)").css({ display: "none"});
		})
			.appendTo($pager).addClass('clickable');
		}
		$('<span class="view-all">View All</span>').bind('click', {'newPage':page}, function(event) {
			$(this).addClass('active').siblings().removeClass('active');
			currentPage = 0;
			numPerPage = numRows;
			$table.trigger('repaginate');
		}).appendTo($pager).addClass('clickable');
			$pager.find('span.page-number:first').addClass('active');
			$pager.insertAfter($table);
			$table.trigger('repaginate');
		});
		
		//Check for rows not in the results and fix for rows that still show
		$("#registrars table.roundBoxTable tr:not(.results)").css({ display: "none"});
	});

	//Search if Domain is clicked
	$("#filter .filters #f3-fly div ul li a").click(function(){
		//Close Other Boxes
		$("#f1").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f1-fly").css({ display : "none"});
		$("#f2").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f2-fly").css({ display : "none"});
		$("#f3").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f3-fly").css({ display : "none"});
	
		//Get filter type
		var filter = $(this).html();
		
		//Hide & Reset all rows
		$("#registrars table.roundBoxTable tr").hide();
		$("#registrars table.roundBoxTable tr").removeClass("rowColor");
		$("#registrars table.roundBoxTable tr").removeClass("results");
		
		//Filter Rows
		$("#registrars table.roundBoxTable tr td.tld:contains('" + filter + "')").each(function(){
			$(this).parent().show();
			$("#registrars table.roundBoxTable tr").not(":hidden").addClass("results");
		});
		
		//Apply Row Background Color to results
		$().find("#registrars table.roundBoxTable tr").not(":hidden").filter(":even").addClass("rowColor");
		
		//Re-Paginate Results
		$("div.pager").remove();
		$('table.paginated').each(function() {
			var currentPage = 0;
			var numPerPage = 50;
			var $table = $(this);
		
			$table.bind('repaginate', function() {
				$table.find('tbody tr.results').show()
				.slice(0,currentPage * numPerPage)
				.hide()
				.end()
				.slice((currentPage + 1) * numPerPage)
				.hide()
			.end();
		});
		
		var numRows = $table.find('tbody tr.results').length;
		var numPages = Math.ceil(numRows / numPerPage);
		var $pager = $('<div class="pager"></div>');
		
		for (var page = 0; page < numPages; page++) {
			$('<span class="page-number">' + (page + 1) + '</span>')
			.bind('click', {'newPage': page}, function(event) {
			currentPage = event.data['newPage'];
			numPerPage = 50;
			$table.trigger('repaginate');
			$(this).addClass('active').siblings().removeClass('active');
			$("#registrars table.roundBoxTable tr:not(.results)").css({ display: "none"});
		})
			.appendTo($pager).addClass('clickable');
		}
		$('<span class="view-all">View All</span>').bind('click', {'newPage':page}, function(event) {
			$(this).addClass('active').siblings().removeClass('active');
			currentPage = 0;
			numPerPage = numRows;
			$table.trigger('repaginate');
		}).appendTo($pager).addClass('clickable');
			$pager.find('span.page-number:first').addClass('active');
			$pager.insertAfter($table);
			$table.trigger('repaginate');
		});
		
		//Check for rows not in the results and fix for rows that still show
		$("#registrars table.roundBoxTable tr:not(.results)").css({ display: "none"});
	});
	
	//Clear All filters and show full list
	$("#clearAll").click(function(){
		//Close Other Boxes
		$("#f1").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f1-fly").css({ display : "none"});
		$("#f2").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f2-fly").css({ display : "none"});
		$("#f3").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f3-fly").css({ display : "none"});
		
		//Hide & Reset all rows
		$("#registrars table.roundBoxTable tr").hide();
		$("#registrars table.roundBoxTable tr").removeClass("rowColor");
		$("#registrars table.roundBoxTable tr").removeClass("results");

		//Apply Row Background Color to results
		$().find("#registrars table.roundBoxTable tr").filter(":even").addClass("rowColor");
		
		//Show all rows
		$("#registrars table.roundBoxTable tr").show();
		
		//Re-Paginate Results
		$("div.pager").remove();
		$('table.paginated').each(function() {
			var currentPage = 0;
			var numPerPage = 50;
			var $table = $(this);
		
			$table.bind('repaginate', function() {
				$table.find('tbody tr').show()
				.slice(0,currentPage * numPerPage)
				.hide()
				.end()
				.slice((currentPage + 1) * numPerPage)
				.hide()
			.end();
		});
		
		var numRows = $table.find('tbody tr').length;
		var numPages = Math.ceil(numRows / numPerPage);
		var $pager = $('<div class="pager"></div>');
		
		for (var page = 0; page < numPages; page++) {
			$('<span class="page-number">' + (page + 1) + '</span>')
			.bind('click', {'newPage': page}, function(event) {
			currentPage = event.data['newPage'];
			numPerPage = 50;
			$table.trigger('repaginate');
			$(this).addClass('active').siblings().removeClass('active');
		})
			.appendTo($pager).addClass('clickable');
		}
		$('<span class="view-all">View All</span>').bind('click', {'newPage':page}, function(event) {
			$(this).addClass('active').siblings().removeClass('active');
			currentPage = 0;
			numPerPage = numRows;
			$table.trigger('repaginate');
		}).appendTo($pager).addClass('clickable');
			$pager.find('span.page-number:first').addClass('active');
			$pager.insertAfter($table);
			$table.trigger('repaginate');
		});		
	});
	
	//Close Other Boxes if clicked outside of the filters
	$(document).click(function(){
		$("#f1").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f1-fly").css({ display : "none"});
		$("#f2").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f2-fly").css({ display : "none"});
		$("#f3").css({ backgroundImage : "url(/images/naming/filter-bg.gif)"});
		$("#f3-fly").css({ display : "none"});
	});

});