$(document).ready(function() {
	$('.tuberip_search,.feeling_search,#tabLatest,#tabHighest,.vidHover').append('<span class="hover"></span>').each(function () {
			var $span = $('> span.hover', this).css('opacity', 0);
			$(this).hover(function () {
				$span.stop().fadeTo(500, 1);
		}, function () {
		$span.stop().fadeTo(900, 0);
			});
	});
});

/* ########################### */
/*    JQuery SF-MENU Plugin    */
/* ########################### */
$(function(){
	// Preload suckerfish images
	var img_a = new Image();
	img_a.src = "/images/submenu_hover.gif";
	var img_b = new Image();
	img_b.src = "/images/BgMenu_hover.gif";

	$('ul.sf-menu').superfish({
		autoArrows:	false, // disable generation of arrow mark-up 
		dropShadows:	false,  // disable drop shadows 
		animation: {height:'show'},
		delay:	800 // The time before hide sub-menu list TEAM CMP operate here i think ;-)
	});
});

/* ########################## */
/*    LOGIN LIGHTBOX SETUP    */
/* ########################## */
$(document).ready(function() {
	$(".login").fancybox({
		'titleShow':	false,
		'overlayColor':	'#000',
		'overlayOpacity':	0.8,
		'width':	870,
		'height':	350,
		'autoScale':	false,
		'scrolling':	'no',
		'onClosed' :	function() {
			$("#login_error").hide();
		},
		'onComplete':	function() {
			$('#login_name').focus();
		}
	});

	$("#login_form").bind("submit", function() {
		if ($("#login_name").val().length < 1 || $("#login_pass").val().length < 1) {
			$("#login_error").show();
			$.fancybox.resize();
			return false;
		}

		$.fancybox.showActivity();
		$.ajax({
			type:		"POST",
			cache:		false,
			url:		"/json/login.php",
			data:		$(this).serializeArray(),
			dataType:	'json',
			success:	finishLogin
		});
		return false;
	});
});

function finishLogin(data, textStatus) {
	$.fancybox.hideActivity();

	if (!data['ok']) {
		$('#login_error').html("Invalid login.");
		$('#login_error').show();
		return false;
	}
	location.reload();
}

function logmeout() {
	$.ajax({
		type: 'POST',
		cache: false,
		url: '/json/logout.php',
		dataType: 'json',
		success: location.reload
	});
	return false;
}

/* ############################# */
/*    DOWNLOAD LIGHTBOX SETUP    */
/* ############################# */
/*$(document).ready(function() {
	$(".downloadBT").fancybox({
		'titleShow':	false,
		'overlayColor':	'#000',
		'overlayOpacity':	0.8,
		'width':	870,
		'height':	675,
		'autoScale':	false,
		'scrolling':	'no',
		'type':	'iframe',
		'onClosed' :	function() {
			$("#DL_error").hide();
		}
	});
*/
$("#register_form").bind("submit", function() {
	
	if ($("#register_name").val().length < 1 || $("#register_pass").val().length < 1) {
		$("#DL_error").show();
		$.fancybox.resize();
			return false;
			}

$.fancybox.showActivity();

	$.ajax({
		type :	"POST",
		cache :	false,
		url :	"data/register.php",
		data :	$(this).serializeArray(),
		success :	function(data) {
			$.fancybox(data);
			}
		});

		return false;
	});


/* ############################# */
/*    SIGNUP LIGHTBOX SETUP    */
/* ############################# */
/*$(document).ready(function() {
	$(".sign").fancybox({
		'titleShow':	false,
		'overlayColor':	'#000',
		'overlayOpacity':	0.8,
		'width':	670,
		'height':	455,
		'autoScale':	false,
		'scrolling':	'no',
		'type':	'iframe',
		'onClosed' :	function() {
			$("#DL_error").hide();
		}
	});
});*/	

$("#register_form").bind("submit", function() {
	
	if ($("#register_name").val().length < 1 || $("#register_pass").val().length < 1) {
		$("#DL_error").show();
		$.fancybox.resize();
			return false;
			}

$.fancybox.showActivity();

	$.ajax({
		type :	"POST",
		cache :	false,
		url :	"data/register.php",
		data :	$(this).serializeArray(),
		success :	function(data) {
			$.fancybox(data);
			}
		});

		return false;
	
});


$(document).ready(function() {
	// Define what happens when the textbox comes under focus
	// Remove the watermark class and clear the box
	$("#s").focus(function() {
		if ($(this).val() == '' || $(this).val() == 'Search. Find. Cum.') {
			$(this).removeClass('watermarkOn').val('');
		}
	});

	// Define what happens when the textbox loses focus
	// Add the watermark class and default text
	$("#s").blur(function() {
		if ($(this).val() == '') {
			$(this).addClass('watermarkOn').val('Search. Find. Cum.');
		}
	});

	// Give the search box focus on page load
	$('#s').focus();
    
    // Define what happens when the textbox comes under focus
    // Remove the watermark class and clear the box
    $("#s2").focus(function() {

        $(this).filter(function() {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == "" || $(this).val() == "Search. Find. Cum."

        }).removeClass("watermarkOn").val("");

    });

    // Define what happens when the textbox loses focus
    // Add the watermark class and default text
    $("#s2").blur(function() {

        $(this).filter(function() {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == ""

        }).addClass("watermarkOn").val("Search. Find. Cum.");

    });

});

function testCode() {
	alert('tg');
}


var TubeRipObject=null;
function downloadvids() {
	TubeRipObject.Download();
}

function showDonationNag() {
		$.fancybox({
			'padding':		0,
			'href':			'#donate-confirm'
		});
		
}

	function declineDonation() {
		$('#no_nag').val(1);
		$.fancybox.close();
	}

	function startDonation() {
		$('#no_nag').val(1);
		window.open('https://secure3.vend-o.com/form.php?site_id=7317&username=ignore&password=ignore&username_hide=1&password_hide=1&logindata=0&logindata_hide=1',
		            'trdonations',
			    'width=700,height=600,location=yes,menubar=yes,resizable=yes,scrollbars=yes');
		$.fancybox.close();
	}

function showinstall(type) {
	var os = "#install_" + type;
		$.fancybox({
			'padding':		10,
			'href':			os,
			'overlayColor':	'#000',
			'overlayOpacity':	0.8
		});
		
}

function closeinstall() {
		$.fancybox.close();
}

$(document).ready(function(){
	ShowPanel();
 	function ShowPanel(panel){
		$("div#nextvid").delay(2000).animate({"left":"0px"},400);
       
 	};
});


/* ############################## */
/*    VIDEOS SINGLE TABS SETUP    */
/* ############################## */
$(document).ready(function() {

	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("active").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("active"); //Remove any "active" class
		$(this).addClass("active"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});

});

/* ############################## */
/*      COMMENTS INPUT TOGGLE     */
/* ############################## */
$(document).ready(function(){
	$("input.tog").click(function(){
		ShowPanel("div.togcont");
	});
	$('#hideCom').click(function(){
		HidePanel("div.togcont");
	});

	function ShowPanel(panel){
		$("div.togcont").animate({"top":"-252px"},500,function(){
			$("#comment_container").hide();
		});
	};
	function HidePanel(panel){
		$("div.togcont").animate({"top":"252px"},500,function(){
			$("#comment_container").hide();
		});
	};

});

