// Refactored from home page
function mapTabs(id,id2,lat,lng,zom)
{
	document.getElementById('map_'+id).style.background='url('+rootPath+'images/tab_blue.jpg) no-repeat top left';
	document.getElementById('map_'+id).style.color = '#ffffff';
	document.getElementById('map_'+id2).style.background='url('+rootPath+'images/tab_white.jpg) no-repeat top left';
	document.getElementById('map_'+id2).style.color = '#417bbf';
	map.setZoom(zom);
	map.setCenter(new GLatLng(lat,lng));
}

function submit_search(countrycity)
{		
	var objForm = document.product_search;
	objForm.product_type.value='16';
	objForm.product_catid.value='2';
	objForm.product_cat.value='Tours';
	objForm.product_type_name.value='Escorted Tours';
	objForm.keyword.value='';
	objForm.country_ID.value='';
	objForm.country.value=countrycity;
	objForm.submit();
}

var ajaxb = new sack();
var ajaxc = new sack();
function getHotDeals(productType,pageNum,pageType,auto) {
//	prompt('',productType+'/'+pageNum+'/'+pageType)
	if (pageType==0)
		varPageType='bestdeals';
	else if (pageType==1)
		varPageType='topdestinations';
	else
		varPageType='bestdeals';
	var ajax = ajaxb;
	var roller = deals;
	var curroll = curdeal;
	if (varPageType!='bestdeals') {
		ajax = ajaxc;
		roller = counts;
		curroll = curcount;
		clearTimeout(timerc);
	} else {
		clearTimeout(timerb);
	}
	if (!auto) {
		// update the rollers (deals or counts) state
		if (varPageType!='bestdeals') {
			cflow = 1;
		} else {
			bflow = 1;
		}
		if (roller[curroll].type != productType) {
			for (var i = 0; i < roller.length; i++) {
				if (roller[i].type == productType) {
					curroll = i;
					if (varPageType!='bestdeals')
						curcount = curroll;
					else
						curdeal = curroll;
					break;
				}
			}
		}
		roller[curroll].pos = pageNum;
	}
//document.getElementById('page_label').innerHTML=deals[curdeal].type+':'+deals[curdeal].pos+' '+bvpaused+' '+bhpaused+'/'+
//counts[curcount].type+':'+counts[curcount].pos+' '+cvpaused+' '+chpaused+'<br/>';
	ajax.requestFile = rootPath+'ajax_bestdeals.asp?type='+varPageType+'&producttype='+productType+'&pagenum='+pageNum;
	if (varPageType=='bestdeals')
		ajax.onCompletion = bestDealsArrived;
	else
		ajax.onCompletion = topDestArrived;
	ajax.runAJAX();
}

function bestDealsArrived() {
	document.getElementById('products_bestdeals').innerHTML=ajaxb.response;
	var obj = document.getElementById('bestdealsbtns0');
	if (obj) {
		if (bvpaused && obj.className == 'column1_header') {
			obj.className = 'column1_header_paused';
			obj.getElementsByTagName('div')[2].title = 'PLAY';
		}
	}
	obj = document.getElementById('bestdealsbtns1');
	if (obj) {
		if (bhpaused && obj.className == 'h_next') {
			obj.className = 'h_next_paused';
			obj.getElementsByTagName('div')[1].title = 'PLAY';
		}
	}
	timerb = setTimeout("rollDeal()",DEALS_INTERVAL);
}

function topDestArrived() {
	document.getElementById('products_topdestinations').innerHTML=ajaxc.response;
	var obj = document.getElementById('topdestsbtns0');
	if (obj) {
		if (cvpaused && obj.className == 'column1_header') {
			obj.className = 'column1_header_paused';
			obj.getElementsByTagName('div')[2].title = 'PLAY';
		}
	}
	obj = document.getElementById('topdestsbtns1');
	if (obj) {
		if (chpaused && obj.className == 'h_next') {
			obj.className = 'h_next_paused';
			obj.getElementsByTagName('div')[1].title = 'PLAY';
		}
	}
	timerc = setTimeout("rollTop()",DEALS_INTERVAL);
}

var bvpaused = false;
var bhpaused = false;
var cvpaused = false;
var chpaused = false;
function pauseHotDeals(pageType,direction) {
	var objid = null;
	var bstopped = false;
	var cstopped = false;
	if (pageType == 0) {
		objid = 'bestdealsbtns' + direction;
		bstopped = bvpaused && bhpaused;
	} else {
		objid = 'topdestsbtns' + direction;
		cstopped = cvpaused && chpaused;
	}
	if (objid) {
		var obj = document.getElementById(objid);
		var paused = false;
		if (obj) {
			if (direction == 0) {
				if (obj.className == 'column1_header') {
					obj.className = 'column1_header_paused';
					obj.getElementsByTagName('div')[2].title = 'PLAY';
				} else {
					obj.className = 'column1_header';
					obj.getElementsByTagName('div')[2].title = 'PAUSE';
				}
				paused = obj.className == 'column1_header_paused';
			} else {
				if (obj.className == 'h_next') {
					obj.className = 'h_next_paused';
					obj.getElementsByTagName('div')[1].title = 'PLAY';
				} else {
					obj.className = 'h_next';
					obj.getElementsByTagName('div')[1].title = 'PAUSE';
				}
				paused = obj.className == 'h_next_paused';
			}
			if (pageType == 0) {
				if (direction == 0)
					bvpaused = paused;
				else
					bhpaused = paused;
			} else {
				if (direction == 0)
					cvpaused = paused;
				else
					chpaused = paused;
			}
			if (pageType == 0 && bstopped) {
				timerb = setTimeout("rollDeal()",DEALS_INTERVAL);
			} else if (pageType == 1 && cstopped) {
				timerc = setTimeout("rollTop()",DEALS_INTERVAL);
			}
		}
	}
}

var timerb, timerc;
var DEALS_INTERVAL = 5000;
var bflow = 0;	// 0-vertical, 1-horizontal
var cflow = 0;
var curdeal = 0;
var curcount = 0;
jQuery(document).ready(function($){
	if (deals.length >= 1) deals[0].pos=1;
	if (counts.length >= 1) counts[0].pos=1;
	timerb = setTimeout("rollDeal()",DEALS_INTERVAL);
	timerc = setTimeout("rollTop()",DEALS_INTERVAL);
});

function rollDeal() {
	if (deals.length > 0 && (!bvpaused || !bhpaused)) {
		if (bflow == 1 && (deals[curdeal].count <= 1 || bhpaused))
			bflow = 0;
		if (bflow == 0 && !bvpaused) {
			curdeal = (curdeal + 1) % deals.length;
		}
		if (!bhpaused)
			deals[curdeal].pos = deals[curdeal].pos % deals[curdeal].count + 1;
		if (!bvpaused)
			bflow = (bflow + 1) % 2;
		getHotDeals(deals[curdeal].type,deals[curdeal].pos,0,1);
	}
}
function rollTop() {
	if (counts.length > 0 && (!cvpaused || !chpaused)) {
		if (cflow == 1 && (counts[curcount].count <= 1 || chpaused))
			cflow = 0;
		if (cflow == 0 && !cvpaused) {
			curcount = (curcount + 1) % counts.length;
		}
		if (!chpaused)
			counts[curcount].pos = counts[curcount].pos % counts[curcount].count + 1;
		if (!cvpaused)
			cflow = (cflow + 1) % 2;
		getHotDeals(counts[curcount].type,counts[curcount].pos,1,1);
	}
}

function BDItem(type,count) {
this.type=type;
this.count=count;
this.pos=count;
}
var deals = new Array();
var counts = new Array();
