
// Activates the rollovers for the images in the code
function activateRollovers() {
	$('.btnRollover').bind('mouseover', function() {
		var sSrc = $(this).attr('src');
		$(this).attr('src', sSrc.replace('normal', 'over'));
	});
	$('.btnRollover').bind('mouseout', function() {
		var sSrc = $(this).attr('src');
		$(this).attr('src', sSrc.replace('over', 'normal'));
	});
}

// Loads the modal depending on the option that is sent through
function loadModal(oArgs) {
	//console.log( oArgs );
	//alert( oArgs._a );
	if (oArgs._a == 'vote') {
		if ( bLoggedIn ) {
			callVote();
		}
		else {
			NickFlashModalLoginJS( URLEncode( window.location ) );
		}
	}
	if (oArgs._a == 'news') {
		callNews(oArgs);
	}
	if (oArgs._a == 'blog') {
		callBlog(oArgs);
	}
	if (oArgs._a == 'flipbook') {
		callFlipbook();
	}
	if (oArgs._a == 'hostinfo') {
		callHostInfo(oArgs);
		
	}
	if (oArgs._a == 'sohotrightnow') {
		if ( bLoggedIn ) {
			callSoHotRightNow();
		}
		else {
			NickFlashModalLoginJS( URLEncode( window.location ) );
		}
	}
	if (oArgs._a == 'watch') {
		callWatch(oArgs);
	}
	if (oArgs._a == 'winnergallery') {
		callWinnerGallery(oArgs);
	}
	if (oArgs._a == 'video') {
		callVideo(oArgs);
	}
	if (oArgs._a == 'showtime') {
		callShowtime(oArgs);
	}
	//window.location = '#/'+oArgs._a;
	var oModalOptions = {
		opacity :0,
		minWidth :968,
		maxWidth :968,
		minHeight :578,
		maxHeight :578,
		overlayCss : {
			background :'#FFFFFF'
		},
		escClose :false
	};
	$('.contentModal').modal(oModalOptions);
	activateRollovers();
}

function closeModal() {
	//window.location = '#/';
	$.modal.close( );
}

// calls the vote ajax content
function callVote(sAction) {
	if (sAction == undefined) {
		sAction = 1;
	}
	$.ajax( {
		url :"vote/",
		data :"ca=" + sAction,
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
			$(document).pngFix();
		}
	});
}
function callSoHotRightNow(sAction) {
	if (sAction == undefined) {
		sAction = 1;
	}
	$.ajax( {
		url :"sohotrightnow/",
		data :"ca=" + sAction,
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
			$(document).pngFix();
		}
	});
}

function callNews( oArgs ) {
	var urlAppend = '';
	if( oArgs._i ) {
		urlAppend = '?item='+oArgs._i;
	}
	$.ajax( {
		url :"news/"+urlAppend,
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
		}
	});
}

function callBlog( oArgs ) {
	var urlAppend = '';
	if( oArgs._i ) {
		urlAppend = '?item='+oArgs._i;
	}
	$.ajax( {
		url :"blog/"+urlAppend,
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
		}
	});
}

function callHostInfo( oArgs ) {
	var urlAppend = '';
	
	if( oArgs._i ) {
		urlAppend = '?item='+oArgs._i;
	}
	$.ajax( {
		url :"host-info/"+urlAppend,
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
		}
	});
}

function callWatch( oArgs ) {
	var urlAppend = '';
	
	if( oArgs._i ) {
		urlAppend = '?item='+oArgs._i;
	}
	$.ajax( {
		url :"watch/"+urlAppend,
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
		}
	});
}

function callVideo( oArgs ) {
	var urlAppend = '';
	
	if( oArgs._i ) {
		urlAppend = '?item='+oArgs._i;
	}
	$.ajax( {
		url :"video/"+urlAppend,
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
		}
	});
}

function callShowtime( oArgs ) {
	var urlAppend = '';
	
	if( oArgs._i ) {
		urlAppend = '?item='+oArgs._i;
	}
	$.ajax( {
		url :"showtime/"+urlAppend,
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
		}
	});
}

// calls the flipbook content
function callFlipbook() {
	$.ajax( {
		url :"flipbook/",
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
			
		}
	});
}

function callWinnerGallery() {
	$.ajax( {
		url :"winners_gallery/",
		cache :false,
		success : function(html) {
			$("#ModalBox").html(html);
			
		}
	});
}

function URLEncode (clearString) {
	  var output = '';
	  var x = 0;
	  clearString = clearString.toString();
	  var regex = /(^[a-zA-Z0-9_.]*)/;
	  while (x < clearString.length) {
	    var match = regex.exec(clearString.substr(x));
	    if (match != null && match.length > 1 && match[1] != '') {
	    	output += match[1];
	      x += match[1].length;
	    } else {
	      if (clearString[x] == ' ')
	        output += '+';
	      else {
	        var charCode = clearString.charCodeAt(x);
	        var hexVal = charCode.toString(16);
	        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
	      }
	      x++;
	    }
	  }
	  return output;
	}
