$(document).ready(function(){

       // $(document).bind("contextmenu",function(e){ return false; });

	$(function($) {
		// $('#BBClock').jclock();
		$("#chatmsg").hide();
		$("#chatsend").hide();
		return false;
	});
	$("div#CBF").mouseover(function () { $(this).css('background-color','aaaaaa'); 	$(this).css('color','ffffff'); return false; });
	$("div#CBF").mouseout(function () { $(this).css('background-color','transparent'); $(this).css('color','000000'); return false; });
	$("div#CBF").click(function () { $("#CBFL").slideToggle(400); return false; });

	//$("div#CBGF").mouseover(function () { $(this).css('background-color','aaaaaa'); 	$(this).css('color','ffffff'); return false; });
	//$("div#CBGF").mouseout(function () { $(this).css('background-color','transparent'); $(this).css('color','000000'); return false; });
	//$("div#CBGF").click(function () { $("#CBGFL").slideToggle(400); return false; });
	
	$("div#CBGFLC").mouseover(function () { ChatScroll = false; $("div#chatwindow").css('background-color','aaaaaa'); });
	$("div#CBGFLC").mouseout(function () { ChatScroll = true; $("div#chatwindow").css('background-color','transparent'); });
	$("div#chatwindow").mouseover(function () { ChatScroll = false; $(this).css('background-color','aaaaaa'); });
	$("div#chatwindow").mouseout(function () { ChatScroll = true; $(this).css('background-color','transparent'); });
	
	$("div#CBGF").click(function () { $("#CBGFL").slideToggle(400); if($(this).width() <= 175) { $(this).animate({width: "543px"},400); $("#chatmsg").show(); $("#chatsend").show(); } else { $(this).animate({width: "175px"},400); $("#chatmsg").hide(); $("#chatsend").hide(); } }	).children().click(function(e) { return false;});
    $("p#chatlink").click(function () { $("#CBGFL").slideToggle(400); if($("div#CBGF").width() <= 175) { $("div#CBGF").animate({width: "543px"},400); $("#chatmsg").show(); $("#chatsend").show(); } else { $("div#CBGF").animate({width: "175px"},400); $("#chatmsg").hide(); $("#chatsend").hide(); } }	).children().click(function(e) { return false;});
	
    //$(".example").click(function(){ $(this).fadeOut("fast"); }).children().click(function(e) { return false;});	
	
	//$("div#CBGF").hoverIntent({ sensitivity: 5, interval: 250, over: makeShow, timeout: 500, out: makeHide });
	

	$("a#ChatMinimizeLink").click(function () { $("#CBGFL").slideToggle(400); if($("#CBGF").width() <= 175) { $("#CBGF").animate({width: "543px"},400); $("#chatmsg").show(); $("#chatsend").show(); } else { $("#CBGF").animate({width: "175px"},400); $("#chatmsg").hide(); $("#chatsend").hide(); } }	).children().click(function(e) { return false;});
	$("li#ChatMinimize").click(function () { $("#CBGFL").slideToggle(400); if($("#CBGF").width() <= 175) { $("#CBGF").animate({width: "543px"},400); $("#chatmsg").show(); $("#chatsend").show(); } else { $("#CBGF").animate({width: "175px"},400); $("#chatmsg").hide(); $("#chatsend").hide(); } }	).children().click(function(e) { return false;});
	

	$("a#ministest").click(function () { $.ajax({url: "messages.php", cache: false, success: function(html){ $("div#INNERPAGE").empty().append(html); return false; }}); });


	//$.getJSON("ajax.php", function(data) { $.each(data.items, function(i,item) { $("<img/>").attr("src", item.media.m).appendTo("#CBFL"); if ( i == 3 ) return false; 	}); });

       /* Support System */
       $('div.demo-show> div.supportpost').hide();
       $('div.demo-show> span.supporttask').click(function() {
              var $nextDiv = $(this).next();
              var $visibleSiblings = $nextDiv.siblings('div.supportpost:visible');
              var ids = $nextDiv.attr('id').split('_');
              var id = (ids[(ids.length-1)]);
       $(function() { $nextDiv.load('ajax/support-task.php?function=showtask&id=' + id).slideToggle('fast'); });
       $(function() { if ($visibleSiblings.length ) { $visibleSiblings.slideUp('fast'); }});
       });

      /* Top bar HNR link */
			$("#myHNR").fancybox({'autoDimensions' : true, 'type' : 'ajax', 'padding' : 1, 'easingIn' : 'swing','transitionIn' : 'elastic', 'scrolling' : 'no', 'onComplete'	:	function() { $("#fancybox-wrap").css('height',552); }});
			$("#allHNR").fancybox({'autoDimensions' : true, 'type' : 'ajax', 'padding' : 1, 'easingIn' : 'swing','transitionIn' : 'elastic', 'scrolling' : 'no', 'onComplete'	:	function() { $("#fancybox-wrap").css('height',552); }});
			
			/* UserDetails Torrent Activity link */
			$("#profileTorrentActivity").fancybox({'autoDimensions' : true, 'type' : 'ajax', 'padding' : 1, 'easingIn' : 'swing','transitionIn' : 'elastic', 'scrolling' : 'no', 'onComplete'	:	function() { $("#fancybox-wrap").css('height',552); }});
			
			/* CPX SiteStats link */
			$("#admin-SiteStats").fancybox({'autoDimensions' : true, 'type' : 'ajax', 'padding' : 1, 'easingIn' : 'swing','transitionIn' : 'elastic', 'scrolling' : 'no', 'onComplete' : function() { $("#fancybox-wrap").css('height',552); }});

			/* User details */
			$("a#SNATCHED").click(function () { $("#SNATCHEDCONTENT").slideToggle(400); return false; });
			$("a#UPLOADED").click(function () { $("#UPLOADEDCONTENT").slideToggle(400); return false; });
			$("a#SEEDING").click(function () { $("#SEEDINGCONTENT").slideToggle(400); return false; });
			$("a#LEECHING").click(function () { $("#LEECHINGCONTENT").slideToggle(400); return false; });
			
			$("a#DESCRIPTION").click(function () { $("#DESCRIPTIONCONTENT").slideToggle(400); return false; });
			$("#viewNFO").fancybox({'autoDimensions' : true, 'type' : 'ajax', 'padding' : 1, 'easingIn' : 'swing','transitionIn' : 'elastic', 'scrolling' : 'no', 'onComplete'	:	function() { $("#fancybox-wrap").css('height',552); }});
			$("#viewIMDBTRAILER").fancybox({'autoDimensions' : true, 'type' : 'ajax', 'padding' : 1, 'easingIn' : 'swing','transitionIn' : 'elastic', 'scrolling' : 'no', 'onComplete'	:	function() { $("#fancybox-wrap").css('height',552); }});
			$("#viewYOUTUBETRAILER").fancybox({'autoDimensions' : true, 'type' : 'ajax', 'padding' : 1, 'easingIn' : 'swing','transitionIn' : 'elastic', 'scrolling' : 'no', 'onComplete'	:	function() { $("#fancybox-wrap").css('height',477); }});

			$("#newUpload").fancybox({'autoDimensions' : true, 'hideOnOverlayClick' : false, 'type' : 'ajax', 'padding' : 1, 'easingIn' : 'swing','transitionIn' : 'elastic', 'scrolling' : 'no', 'onComplete' : function() { $("#fancybox-wrap").css('height',552); }});
			
			
			$(".thumbsnoaccess img").fadeTo("fast", 0.15); // This sets the opacity of the thumbs to fade down to 60% when the page loads
			$(".thumbs img").fadeTo("fast", 0.40); // This sets the opacity of the thumbs to fade down to 60% when the page loads
      $(".thumbs img").hover(function(){
       $(this).fadeTo("fast", 1.0); // This should set the opacity to 100% on hover
      },function(){
       $(this).fadeTo("slow", 0.40); // This should set the opacity back to 60% on mouseout
      });
      
      $("img:not([title])").each(function() {$(this).attr("title", $(this).attr("alt"))})

	  
	  // AUTO RSS
		$("tr.autorssrowrdy td").click(function(){
			var element = $(this);
			var noteid = element.parent().attr("id");
			var info = 'sid=' + noteid;
			$.ajax({type: "GET",url: "ajax/add_rssdl.php",data: info,success: function(){ 
				element.parent().eq(0).removeClass("autorssrowrdy").addClass("autorssrowadded");
					$.ajax({
					type: "GET",
					cache: false,
					url: "ajax/stat_rssque.php",
					success: function(data){ $("#statrssque").html(data); }
				});
			} });
			return false;
		});
	  
	  //When you click on a link with class of poplight and the href starts with a # 
	$('a.poplight[href^=#]').click(function() {
		var popID = $(this).attr('rel'); //Get Popup Name
		var popURL = $(this).attr('href'); //Get Popup href to define size

		//Pull Query & Variables from href URL
		var query= popURL.split('?');
		var dim= query[1].split('&');
		var popWidth = dim[0].split('=')[1]; //Gets the first query string value

		//Fade in the Popup and add close button
		$('#' + popID).fadeIn().css({ 'width': Number( popWidth ) }).prepend('<a href="#" class="close"><img src="/gfx/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>');

		//Define margin for center alignment (vertical   horizontal) - we add 80px to the height/width to accomodate for the padding  and border width defined in the css
		var popMargTop = ($('#' + popID).height() + 80) / 2;
		var popMargLeft = ($('#' + popID).width() + 80) / 2;

		//Apply Margin to Popup
		$('#' + popID).css({
			'margin-top' : -popMargTop,
			'margin-left' : -popMargLeft
		});

		//Fade in Background
		//$('body').append('<div id="fade"></div>'); //Add the fade layer to bottom of the body tag.
		//$('#fade').css({'filter' : 'alpha(opacity=80)'}).fadeIn(); //Fade in the fade layer - .css({'filter' : 'alpha(opacity=80)'}) is used to fix the IE Bug on fading transparencies 

		return false;
	});

	//Close Popups and Fade Layer
	$('a.close').live('click', function() { //When clicking on the close or fade layer...
		$('.popup_block').fadeOut(function() {
        $('a.close').remove();  //fade them both out
    });
    return false;
});
	  
	  
	  
	  
	  
});

function makeShow(){ $("#CBGFL").show(700); }
function makeHide(){ }

