var AJAX_PATH = '/webmanage_custom/public_panel/ajax/';

function WBM_purity() {
	// dummy function
}

function WBM_controlNewsTicker(direction) {
	$.get(AJAX_PATH + 'news.php', {action: 'ticker', index: $("#news-ticker-index").val(), direction: direction}, function(response) {
		$("#news-ticker").html(response);
	});
}


function WBM_changeContactMap(_location)
{
	if(_location == "map-australia" || _location == "map-usa-office" || _location == "map-usa-postal" || _location == "map-taiwan" || _location == "map-china")
	{
		$("#map-australia").css("display", "none");
		$("#map-usa-office").css("display", "none");
		$("#map-usa-postal").css("display", "none");
		$("#map-china").css("display", "none");
		$("#map-taiwan").css("display", "none");

		$("#"+_location).css("display", "");
	}
}


function nextAffiliateTicker() {
	var total = $('#affiliate-ticker li').length;
	var current = $('#affiliate-ticker li.active').index();
	
	var parse_i = 0;
	$('#affiliate-ticker li').each(function() {
		if ($(this).hasClass('active')) {
			current = parse_i;
		}
		parse_i ++;
	});

	$('#affiliate-ticker li').removeClass('active');

	if (current == total - 1) {
		next = 1;
		$('#affiliate-ticker li:first').addClass('active');
	}
	else {
		next = current + 1;
		$('#affiliate-ticker li:eq(' + next + ')').addClass('active');
	}
		
	return false;
}

$(document).ready(function() {
	if ($('#affiliate-ticker').length) {
		setInterval("nextAffiliateTicker()", 5000);
	}

	$('.search-form form').submit(function() {
		if ($('#frm_search').val() == '' || $('#frm_search').val() == 'Start your search here') {
			$('#frm_search').focus();
			return false;
		}
	});
});

