var AjaxRequest = Class.create({
	initialize: function(domain, controller, id) {
		this.domain = domain;
		this.controller = controller;
		this.id = id;
	},

	getVideoData: function(tab, pagenum, sortby) {

	var url = this.domain+"/"+this.controller+'_tabs.php';
	var rand = Math.random(9999);
	var pars = 'id=' + this.id + '&tab=' + tab + '&rand=' + rand;
	new Ajax.Request(url, {
		  method: 'get',
		  parameters: pars,
		  asynchronous: false,
		  onSuccess: function(transport) {
		  	var result = transport.responseText;
		  	document.getElementById("trailer").className = "";
			document.getElementById("full").className = "";
			document.getElementById("downloads").className = "";
		  	$(tab).className = "active";

			//alert(result);
			if(tab=="trailer")
			{
				$('FlashPlayer').show();
		  		ajaxRequest.getStreamingTrailerPlayer(result);
		  	}
		  	else if(tab=="full")
			{
				$('FlashPlayer').show();
		  		ajaxRequest.getStreamingPlayer(result);
		  	}
		  	else if(tab=="downloads")
		  	{
		  		$('FlashPlayer').innerHTML = "";
				$('FlashPlayer').hide()
				$('Download').show();
				ajaxRequest.replace("Download", result);
		  	}
		  }
		});
	},
		
	getStreamingTrailerPlayer: function(result) {
	var flashvars = {
		'file': result+'',
		'type': 'http',
		'skin': 'http://www.justporno.com/skins/stijl.swf',
		'abouttext': 'justporno',
		'image': 'http://www.justporno.com/images/streampic.jpg',
		'aboutlink': 'http://www.justporno.com'
		};
		var params = {
		allowfullscreen: "true"
		};
		
		$('Download').hide();
		$('FlashPlayer').innerHTML = "<div id=\"flashplayerdiv\">You either have JavaScript turned off or an old version of Adobe's Flash Player. <a href=\"http://www.adobe.com/go/getflashplayer/\" target=\"_blank\">Get the latest Flash player.</a></div>";
		$('FlashPlayer').show();

		swfobject.embedSWF("/mediaplayer.swf", "flashplayerdiv", "640", "480", "9.0.0", "expressInstall.swf", flashvars, params);

	},
	
	getStreamingPlayer: function(result) {
	var flashvars = {
		'file': result+'',
		'type': 'http',
		'skin': 'http://www.justporno.com/skins/stijl.swf',
		'abouttext': 'justporno',
		'aboutlink': 'http://www.justporno.com'
		};
		var params = {
		allowfullscreen: "true"
		};
		
		$('Download').hide();
		$('FlashPlayer').innerHTML = "<div id=\"flashplayerdiv\">You either have JavaScript turned off or an old version of Adobe's Flash Player. <a href=\"http://www.adobe.com/go/getflashplayer/\" target=\"_blank\">Get the latest Flash player.</a></div>";
		$('FlashPlayer').show();

		swfobject.embedSWF("/mediaplayer.swf", "flashplayerdiv", "640", "480", "9.0.0", "expressInstall.swf", flashvars, params);

	},

	getPreviewVideoData: function(tab, pagenum, sortby) {

	var url = this.domain+"/"+this.controller+'_tabs.php';
	var rand = Math.random(9999);
	var pars = 'id=' + this.id + '&tab=' + tab + '&rand=' + rand;
	new Ajax.Request(url, {
		  method: 'get',
		  parameters: pars,
		  asynchronous: false,
		  onSuccess: function(transport) {
		  	var result = transport.responseText;
		  	document.getElementById("trailer").className = "";
			document.getElementById("full").className = "";
			document.getElementById("downloads").className = "";
		  	$(tab).className = "active";

			//alert(result);
			if(tab=="trailer" || tab=="full")
			{
				$('FlashPlayer').show();
		  		ajaxRequest.getPreviewStreamingPlayer(result);
		  	}
		  	else if(tab=="downloads")
		  	{
		  		$('FlashPlayer').innerHTML = "";
				$('FlashPlayer').hide()
				$('Download').show();
				ajaxRequest.replace("Download", result);
		  	}
		  }
		});
	},
	
	getPreviewStreamingPlayer: function(result) {
	var flashvars = {
		'file': result+'',
		'type': 'lighttpd',
		'skin': 'http://www.justporno.com/skins/stijl.swf',
		'abouttext': 'justporno',
		'aboutlink': 'http://www.justporno.com'
		};
		var params = {
		allowfullscreen: "true"
		};
		
		$('Download').hide();
		$('FlashPlayer').innerHTML = "<div id=\"flashplayerdiv\">You either have JavaScript turned off or an old version of Adobe's Flash Player. <a href=\"http://www.adobe.com/go/getflashplayer/\" target=\"_blank\">Get the latest Flash player.</a></div>";
		$('FlashPlayer').show();

		swfobject.embedSWF("/mediaplayer.swf", "flashplayerdiv", "320", "240", "9.0.0", "expressInstall.swf", flashvars, params);

	},

	getTabData: function(tab_id, pagenum, sortby, exclusive) {

	var url = this.domain+"/"+this.controller+'_tabs.php';
	var rand = Math.random(9999);
	var pars = 'id=' + this.id + '&tab=' + tab_id + '&pagenum=' + pagenum + '&sortby=' + sortby + '&exclusive='+exclusive+'&rand=' + rand;
	new Ajax.Request(url, {
		  method: 'get',
		  parameters: pars,
		  asynchronous: false,
		  onSuccess: function(transport) {
		  	var result = transport.responseText;
		  	document.getElementById("tab1").className = "";
			document.getElementById("tab2").className = "";
			document.getElementById("tab3").className = "";
		  	$("tab"+tab_id).className = "active";
		  	ajaxRequest.replace('content', result);
		  }
		});
	},
	
	getCommentData: function(id, pagenum) {

	var url = this.domain+'/ajax_comments.php';
	var rand = Math.random(9999);
	var pars = 'id=' + id + '&type=' + this.controller + '&pagenum=' + pagenum + '&rand=' + rand;
	new Ajax.Request(url, {
		  method: 'get',
		  parameters: pars,
		  asynchronous: false,
		  onSuccess: function(transport) {
		  	var result = transport.responseText;
		  	ajaxRequest.replace('page_contents', result);
		  }
		});
	},
		
	addFavorite: function() {
	
	var url = this.domain+'/add_favorite.php';
	var pars = 'id='+this.id+'&type='+this.controller+'&action=add';
	new Ajax.Request(url, {
		  method: 'get',
		  parameters: pars,
		  asynchronous: false,
		  onSuccess: function(transport) {
		  	var result = transport.responseText;
		  	ajaxRequest.replace('favorite', result);
		  }
		});
	},
	
	addDLHit: function() {
	
	var url = this.domain+'/stats.php';
	var pars = 'id='+this.id+'&hit=dl';
	new Ajax.Request(url, {
		  method: 'get',
		  parameters: pars,
		  asynchronous: false,
		  onSuccess: function(transport) {

		  }
		});
	},
	
	replace: function(elemId, msg) {
		$(elemId).innerHTML = msg;
	}

});
