//------------------------------------------------------[TG]
// Public: JS
//------------------------------------------------------[TG]

// Event Delegation ------------------------------------[TN]
jQuery.delegate = function(Rules) {
	return function(e) {
		var Target = $(e.target);
		for (var Selector in Rules)
			if (Target.is(Selector)) return Rules[Selector].apply(this, $.makeArray(arguments));
	}
}
//------------------------------------------------------[TN]

jQuery.fn.debug = function() {
	return this.each(function(){
		var verbose = false;
		var itemsPerPage = 10;
		var myHeader  = '//VPI_JS_Debug-----------------------------------------------' + "\n";
			myHeader += (this['tagName'] != null) ? 'Tag Name: ' + this['tagName'] + "\n" : '';
			myHeader += 'Type: ' + (typeof this) + "\n";

		var myFooter  = "\n\n" + '//----------------------------------------------------------------';
		var z = 0;
		var y = 0;
		var mySplit = 'Page [' + ++y + ']' + "\n" + '//----------------------------------------------------------------' + "\n\n";
		var myMessage = '';
		for(var i in this) {
			if (i == 'domConfig' || typeof this[i] == 'unknown')
				continue;
			if(!verbose && typeof this[i] == 'function')
				continue;
			myMessage += '[' + i + '] -> ' +
				((!verbose && (typeof this[i] == 'string') && (this[i].length > 200)) ?
					this[i].substr(0,200) + ' {...}' :
					this[i])
				+ "\n";
			if(z++ > itemsPerPage) {
				alert(myHeader + mySplit + myMessage + myFooter);
				z = 0;
				mySplit = 'Page [' + ++y + ']' + "\n" + '//----------------------------------------------------------------' + "\n\n";
				myMessage = '';
			}
		}
		alert(myHeader + mySplit + myMessage + myFooter);
	});
};



function PollLoaded() {
	$('.PollSubmit').click(PollSubmit);
	$('.PollResult').click(PollResult);
}


function GetHoroscope(Sign, MySectionID) {
	$('#horoscopeContent').fadeOut("slow", HoroscopeCallback(Sign, MySectionID)).fadeIn("slow"); 
	return false;
}

function HoroscopeCallback (Sign, MySectionID) {
	$('#horoscopeContent').load('/ajx.horoscope.get/',{'Sign': Sign, 'SectionID':MySectionID});
//	$('#horoscopeContent').fadeIn('slow');
}

function GetPopular(Type,Category,SectionID,Tags) {
	Category = ( Category ) ? Category : 'Article';
	if(Type =='Viewed'){
		$('#ViewedLink').attr('class','Popular_Selected');
		$('#SharedLink').attr('class','Popular_notselected');
	}
	else {
		$('#ViewedLink').attr('class','Popular_notselected');
		$('#SharedLink').attr('class','Popular_Selected');
	}

	$('#Most_Popular_Content').fadeOut("slow", PopularCallback(Type,Category,SectionID,Tags)).fadeIn("slow"); 
	return false;
}


function PopularCallback (Type,Category,SectionID,Tags) {
		$('#Most_Popular_Content').load('/ajx.popular.get',{'PopularType': Type,'Category':Category,'SectionID':SectionID,'Tags':Tags});
}

function PollSubmit() {
	// Error check
	

	// Submit to process
	var	PollData = {
		'PollID'	: $('#PollID').val(),
		'ChoiceID'	: $('.PollChoice:checked').val()
	};

	$.post('/poll.process/', PollData, PollResult);

	return false;
}

function PollResult() {
	$('.Poll').load('/poll.result/?PollID=' + $('#PollID').val());
	return false;
}
//------------------------------------------------------[TG]
var moduleClass = function(){};var moduleClass = function(){};

var essenceMod = new moduleClass();
