$(document).ready(function(){

    $("#add_favorites").click(function () {

    	$("#add_favorites").click(function(){return false;});

        $.ajax({

          dataType: 'html',
          url: "?action=favorites_ajax&guimode=ajax&type="+$("#addfavtype").val()+"&id="+$("#addfavid").val()+"&mode=add",
          cache: false,
          async: false,
          success: function(html){
            $("#add_favorites").css('background-position', '-185px 0');
            $(".mamode1").css('background-position', '0 0');
            $("#add_favorites").addClass('emphasis').empty().append(html).unbind().attr("onclick","return false;");
            if (typeof (isTrial) !== "undefined" && isTrial === true && typeof (trialUpgradeUrl) !== "undefined") {
				$.facebox('This video has been added to your favorites successfully. You need to upgrade your membership in order to access your favorites. <h2 style="text-align: center;color: #9A9A9A"><a style="color: #fff;" href="'+trialUpgradeUrl+'">Click here</a> to upgrade your membership now.</h2>')
            }
          }
        });

        return false;

    });


    $("#add_to_wishlist").click(function () {

    	$("#add_to_wishlist").click(function(){return false;});

        $.ajax({

          dataType: 'html',
          url: "?action=favorites_ajax&guimode=ajax&type="+$("#addfavtype").val()+"&id="+$("#addfavid").val()+"&mode=add",
          cache: false,
          async: false,
          success: function(html){
            $("#add_to_wishlist").css('background-position', '-185px 0');
            $("#add_to_wishlist").attr("onclick","return false;").unbind();
            if (typeof (isTrial) !== "undefined" && isTrial === true && typeof (trialUpgradeUrl) !== "undefined") {
				$.facebox('This video has been added to your favorites successfully. You need to upgrade your membership in order to access your favorites. <h2 style="text-align: center;color: #9A9A9A"><a style="color: #fff;" href="'+trialUpgradeUrl+'">Click here</a> to upgrade your membership now.</h2>')
            }
          }
        });

        return false;

    });

    $("#add_scene").click(addScene);
    $("#add_dvd").click(addDvd);
    $("#del_scene").click(delScene);
    $("#del_dvd").click(delDvd);

    $(".add_model").click(function() {
		var clicked_button = $(this);
		var model_id = $(this).parent().find("input").val();
	    $.ajax({
	      dataType: 'html',
	      url: "?action=favorites_ajax&guimode=ajax&type=pornstar&id="+model_id+"&mode=add",
	      cache: false,
	      async: false,
	      success: function(html){
      		// Change button
	        //clicked_button.removeClass('add_model').addClass('del_model');
	        clicked_button.fadeOut();
	        // Add the star
	        $('#model_'+model_id).find('a:first').fadeIn('slow');
	        if (typeof (isTrial) !== "undefined" && isTrial === true && typeof (trialUpgradeUrl) !== "undefined") {
				$.facebox('This model has been added to your favorites successfully. You need to upgrade your membership in order to access your favorites. <h2 style="text-align: center;color: #9A9A9A"><a style="color: #fff;" href="'+trialUpgradeUrl+'">Click here</a> to upgrade your membership now.</h2>')
	        }
	      }
	    });
	    return false;
    });

    $(".del_model").click(function() {
		var clicked_button = $(this);
		var model_id = $(this).parent().find("input").val();
	    $.ajax({
	      dataType: 'html',
		  url: "?action=favorites_ajax&guimode=ajax&id="+model_id+"&mode=remove&type=pornstar",
	      cache: false,
	      async: false,
	      success: function(html){
      		// Change button
	        //clicked_button.removeClass('del_model').addClass('add_model');
	        clicked_button.fadeOut();
	        // Remove the star
	        $('#model_'+model_id).find('a:first').fadeOut('slow');
	      }
	    });
	    return false;
    });
});


function addScene()
{
	//$('#add_scene').one('click', function() {return false;});
	$('#add_scene').unbind('click');
	$.ajax({
      dataType: 'html',
      url: "?action=favorites_ajax&guimode=ajax&type=scene&id="+$("#sceneid").val()+"&mode=add",
      cache: false,
      async: false,
      success: function(html){
        $("#add_scene span:first").removeClass('b_add_scene').addClass('b_rem_scene');
        $("#add_scene span:last").html('Remove Scene').addClass('pink');
        $("#add_scene").attr('id', 'del_scene');
        if (typeof (isTrial) !== "undefined" && isTrial === true && typeof (trialUpgradeUrl) !== "undefined") {
			$.facebox('This video has been added to your favorites successfully. You need to upgrade your membership in order to access your favorites. <h2 style="text-align: center;color: #9A9A9A"><a style="color: #fff;" href="'+trialUpgradeUrl+'">Click here</a> to upgrade your membership now.</h2>')
        }
      }
    });
	$('#del_scene').one('click', delScene);

    return false;
}

function addDvd()
{
	//$('#add_dvd').one('click', function() {return false;});
	$('#add_dvd').unbind('click');
    $.ajax({
      dataType: 'html',
      url: "?action=favorites_ajax&guimode=ajax&type=dvd&id="+$("#dvdid").val()+"&mode=add",
      cache: false,
      async: false,
      success: function(html){
        $("#add_dvd span:first").removeClass('b_add_dvd').addClass('b_rem_dvd');
        $("#add_dvd span:last").html('Remove DVD').addClass('pink');
        $("#add_dvd").attr('id', 'del_dvd');
        if (typeof (isTrial) !== "undefined" && isTrial === true && typeof (trialUpgradeUrl) !== "undefined") {
			$.facebox('This video has been added to your favorites successfully. You need to upgrade your membership in order to access your favorites. <h2 style="text-align: center;color: #9A9A9A"><a style="color: #fff;" href="'+trialUpgradeUrl+'">Click here</a> to upgrade your membership now.</h2>')
        }
      }
    });
	$('#del_dvd').one('click', delDvd);

    return false;
}

function delScene()
{
	//$('#del_scene').one('click', function() {return false;});
	$('#del_scene').unbind('click');
    $.ajax({
      dataType: 'html',
      url: "?action=favorites_ajax&guimode=ajax&type=scene&id="+$("#sceneid").val(),
      cache: false,
      async: false,
      success: function(html){
        $("#del_scene span:first").removeClass('b_rem_scene').addClass('b_add_scene');
        $("#del_scene span:last").html('Add Scene').addClass('pink');
        $("#del_scene").attr('id', 'add_scene');
      }
    });
	$('#add_scene').one('click', addScene);

    return false;
}

function delDvd()
{
	//$('#del_dvd').one('click', function() {return false;});
	$('#del_dvd').unbind('click');
    $.ajax({
      dataType: 'html',
	  url: "?action=favorites_ajax&guimode=ajax&type=dvd&id="+$("#dvdid").val(),
      cache: false,
      async: false,
      success: function(html){
        $("#del_dvd span:first").removeClass('b_rem_dvd').addClass('b_add_dvd');
        $("#del_dvd span:last").html('Add DVD').addClass('pink');
        $("#del_dvd").attr('id', 'add_dvd');
      }
    });
	$('#add_dvd').one('click', addDvd);

    return false;
}
