//Copyright (c) 2009 Trevor Sheridan. All rights reserved.

$(document).ready(function(){
	
	var isopen = false;
	
	$('a.new_window').click(function (e) {
	
		e.preventDefault();
		
		var newWindow = open(this.href);
		
		options.open.call(newWindow, e);
		
	});
	
	$('div#hidden_wrapper').css('top', "-" + quickHeight('div#hidden_wrapper_top') + "px");
	
	$(window).bind('resize', function() {
		
		if(isopen == true) {
		
			$('div#hidden_wrapper').css('top', "0px");
		
			changeCursor('n-resize');
			
		} else {
		
			$('div#hidden_wrapper').css('top', "-" + quickHeight('div#hidden_wrapper_top') + "px");
			
			isopen = false;
			
			changeCursor('s-resize');
		
		}
	
	});
	
	$('#feed_links ul li.active').find('a').animate({ color: "#333333" }, 300, 0);
	
	$('#feed_links ul li a').hover(function() {
		
		if($(this).parent().hasClass('active')) {
		
			//Do nothing
		
		} else {
		
			$(this).css('color', '#e50568');
		
		}
	
	}, function() {
		
		if($(this).parent().hasClass('active')) {
		
			//Do nothing
		
		} else {
		
			$(this).css('color', '#ffffff');
		
		}
	
	});
	
	$('#feed_links ul li').click(function() {
		
		if(!$(this).hasClass('active')) {
		
			$(this).parent().find("li.active a").animate({
						
				color: "#ffffff"
						
			}, 600, 0);
			
			$('div#caption_box div:regex(id,^caption_[0-9]_box$)').removeClass('active');
			
			$('#' + $(this).attr('id') + '_box').addClass('active');
			
			$('div#counter div:regex(id,^caption_[0-9]_box_counter$)').removeClass('active');
			
			$('#' + $(this).attr('id') + '_box_counter').addClass('active');
			
			$(this).parent().parent().find("li.active").removeClass('active');
			
			$(this).find('a').animate({
						
				color: "#333333"
						
			}, 600, 0);
			
			$(this).addClass('active');
			
		}
	
	});
	
	$('#pull').parent().parent().draggable({
		
		appendTo: '#wrapper',
		
		handle: '#pull',
		
		axis: 'y',
		
		snap: true,
		
		snapMode: 'outer',
		
		stop: function(event, ui) {
			
			var currentcss = parseFloat($(this).css('top'));
			
			if(isopen == true) {
				
				if((currentcss > 0 && currentcss <= 40) || (currentcss < 0 && currentcss >= -40)) {
					
					$(this).animate({
					
						top: "0px"
					
					}, 500, 0, changeCursor('n-resize'));
					
					isopen = true;
				
				} else {
				
					$(this).animate({
					
						top: "-" + quickHeight('div#hidden_wrapper_top') + "px"
					
					}, 300, 0, changeCursor('s-resize'));
					
					isopen = false;
				
				}
				
			} else if(isopen == false) {
				
				if(currentcss < "-" + quickHeight('div#hidden_wrapper_top')) {
					
					$(this).animate({
					
						top: "-" + quickHeight('div#hidden_wrapper_top') + "px"
					
					}, 300, 0, changeCursor('s-resize'));
					
					isopen = false;
				
				} else {
				
					$(this).animate({
						
						top: "0px"
						
					}, 500, 0, changeCursor('n-resize'));
					
					isopen = true;
					
				}
			
			}
			
		}
		
	});
	
	function changeCursor(type) {
	
		$('#pull a').css('cursor', type);
		
		return true;
	
	}
	
	function quickHeight(element) {
		
		var height = $(element).eq(0).height();
		
		return height;
		
	}

});