var featuredSiteData = {
	id: new Array(),
	name: new Array(),
	ACTIVE_RECORD : 0,
	IS_PREVIOUS_EXIST : false,
	IS_NEXT_EXIST : false,
	PREVIOUS_REQUEST : 'previous',
	NEXT_REQUEST : 'next'
};
featuredSiteData.init = function (obj) {
	this.id = obj.id;
	this.name = obj.name;
}
featuredSiteData.setActiveRecord = function (activeRecord) {
	this.ACTIVE_RECORD = activeRecord;
}
featuredSiteData.getFeaturedSite = function (requestType) {
	if(this.ACTIVE_RECORD >= this.id.length-1 && requestType == this.NEXT_REQUEST) {
		return;
	}
	if(this.ACTIVE_RECORD == 0 && requestType == this.PREVIOUS_REQUEST) {
		return;
	}
	if(this.NEXT_REQUEST == requestType) {
		this.ACTIVE_RECORD = this.ACTIVE_RECORD + 1;
	}
	else {
		this.ACTIVE_RECORD = this.ACTIVE_RECORD - 1;
	}

	// check wheather the data is rendered previously
	$('.hide_featured_site').hide();
	if(undefined != $('featured_site' + this.ACTIVE_RECORD)) {
		// if yes activate that div
		this.loadFeaturedSite();
	}
	this.loading(true);
	var url = base_url + 'site/featured_site';
	$.post(
		url, 
		{site_id : this.id[this.ACTIVE_RECORD]}, 
		function (data) {
			//render data
			featuredSiteData.loadFeaturedSite(data);
		});
}

featuredSiteData.loadFeaturedSite = function(featuredSiteHtml) {
	if(this.ACTIVE_RECORD == (this.id.length-1)) {
		// disable next button
		$('#featured_site_next').addClass('jcarousel-next-disabled jcarousel-next-disabled-horizontal');
	}
	if(this.ACTIVE_RECORD == 0) {
		// disable previous button
		$('#featured_site_prev').addClass('jcarousel-prev-disabled jcarousel-prev-disabled-horizontal');
	}
	
	if(0 < this.ACTIVE_RECORD && this.ACTIVE_RECORD < (this.id.length-1)) {
		$('#featured_site_prev').removeClass('jcarousel-prev-disabled jcarousel-prev-disabled-horizontal');
		$('#featured_site_next').removeClass('jcarousel-next-disabled jcarousel-next-disabled-horizontal');
	}

	if(undefined != featuredSiteHtml) {
		var outputhtml = '<div id="featured_site' + this.ACTIVE_RECORD + '" style="min-height:352px;" class="hide_featured_site">' + featuredSiteHtml + '</div>';
		$('#featured_site').append(outputhtml);
	}
	$('.hide_featured_site').hide();
	$('#active_featured_site').html(this.ACTIVE_RECORD+1);
	$('#active_featured_site_name').html(this.name[this.ACTIVE_RECORD]);
	$('#featured_site' + this.ACTIVE_RECORD).show();
	this.loading(false);
}

featuredSiteData.loading = function(showLoadingBox) {
	if(showLoadingBox) {
		$('#featured_site_loading').show();
	}
	else {
		$('#featured_site_loading').hide();
	}
}
//featuredSiteData.getFeaturedSite('next');

