function initAd(adZone)
{
	var zone = adZone;
	
	var h2Hi = 0;
	var descHi = 0;
	
	$('.ad', zone).each(function() {
		if ($('h2', this).height() > h2Hi)
			h2Hi = $('h2', this).height();
		if ($('.description', this).height() > descHi)
			descHi = $('.description', this).height();
	});
	
	$('h2', zone).height(h2Hi);
	$('.description', zone).height(descHi);
	
		
}
var Hero = function(container) {
	var self = this;
	var timer = null;
	this.panels = new Array();
	this.currentIndex = 0;

	this.init = function() {
		$('.panel', container).each(function() {
			var path = $(this).attr('data-img');
			var duration = Number($(this).attr('data-duration'));
			var type = (path.match(/\.swf$/i) ? 'flash' : 'image');
			var id = null;
			if (type == 'image') {
				$('a', this).html('<img src="' + path + '" width="503" height="190" border="0" />');
			} 
			else {
				var date = new Date();
				id = 'hero' + i + date.getTime();
				$(this).html('<div id="' + id + '"></div>');
				var flashvars = {};
				var params = {wmode: 'transparent', play: 'false', allowScriptAccess: 'always'};
				var attributes = {id: id, name: id};
				swfobject.embedSWF(path, id, '503', '190', '9', '', flashvars, params, attributes);
			}
			self.panels.push({elem: this, duration: duration, type: type, id: id});
		}).eq(0).addClass('show');
		
		self.buildControls();
		self.play();
		container.removeClass('loading');
	}
	
	this.buildControls = function() {
		var controls = $('<div class="controls"><div class="pagination"></div><span><a class="button btnPause" href="#">Play/Pause</a></span></div>');
		for (var i = 0; i < self.panels.length; i++) {
			$('<span><a href="#">' + (i+1) + '</a></span>').appendTo($('.pagination', controls));
		}
		$('.pagination a', controls).eq(0).addClass('selected');
		
		
		$('.button', controls).click(function() {
			if ($(this).hasClass('btnPlay')) {
				self.play();
			}
			else if ($(this).hasClass('btnPause')) {
				self.pause();
			}
			return false;
		});
		
		$('.pagination a', controls).click(function() {
			var index = Number($(this).text()) - 1;
			self.pause();
			self.gotoIndex(index);
			return false;
		});
		
		var ul = $('ul', container);
		container.append(controls);
	}
	
	

	this.next = function() {
		var nextIndex = self.currentIndex + 1;
		if (self.currentIndex == (self.panels.length - 1)) nextIndex = 0;
		self.gotoIndex(nextIndex);
		var duration = self.panels[nextIndex].duration * 1000;
		self.timer = setTimeout(self.next, duration);
	}
	
	this.gotoIndex = function(nextIndex) {
		if (self.currentIndex == nextIndex) return false;
		
		var currentPanel = self.panels[self.currentIndex ].elem;
		var nextPanel = self.panels[nextIndex].elem;
		
		if (self.panels[self.currentIndex].type == 'flash') {
			var id = self.panels[self.currentIndex].id;
			document.getElementById(id).StopPlay();
			document.getElementById(id).Rewind();
		}
		$(currentPanel).fadeOut().removeClass('show');
		$(nextPanel).fadeIn(500, function() {
			$(this).addClass('show');
			if (self.panels[nextIndex].type == 'flash') {
				var id = self.panels[nextIndex].id;	
				document.getElementById(id).Play();
			}
		});
		self.currentIndex = nextIndex;
		
		$('.pagination a', container).removeClass('selected').eq(nextIndex).addClass('selected');
		//alert(nextIndex);
	}
	
	this.play = function() {
		var duration = self.panels[self.currentIndex].duration * 1000;
		self.timer = setTimeout(self.next, duration);
		$('.controls .button', container).removeClass('btnPlay').addClass('btnPause');
	}
	
	this.pause = function() { 
		clearTimeout(self.timer);
		$('.controls .button', container).removeClass('btnPause').addClass('btnPlay');
	}
	
	this.init();
}

function initClick()
{
	$('.clickableRow').each(function() {
		$(this).hover(function() {
			$(this).addClass('hover');
		},function() {
		   $(this).removeClass('hover');
		});
		
		$(this).click(function() {
			if ($(this).hasClass('opened'))
			{
				$(this).removeClass('opened');
			}
			else
			{
				$(this).addClass('opened');
			}
		});
	});
	
}

function initialRightForm() {
	$('#rightNavProvinceList').val('');
	$('#rightNavType').attr('disabled','disabled');
	$('#rightNavSearchBtn').attr('disabled','disabled');			
}

