$(function(){
	$('.portfolio_entry_description').append('<div id="sliderNav">');	
	$('#slider').cycle({fx: 'fade', speed: 1000, timeout: 4000, pager: '#sliderNav', pauseOnPagerHover: 1, pause: 1});
	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
		slideContent(186, 30, 40);
	} else {
		var _window_w = $(window).width();
		$('#wrapper, #single_entry_container').width(_window_w-30);
	
		$("a[href^=http]").each(
	    	function(){
	        	if(this.href.indexOf(location.hostname) == -1) {
	        		$(this).attr('target', '_blank');
	      		}
	    	}
	  	);
	
		$('#wrapper').fadeIn('slow');
			
		$("li a#client").click(function(){
			if($(this).hasClass('active') == true){
				$("ul#secondary_nav").slideUp(500);
				$(this).removeClass('active');
			} else {
				$("ul#secondary_nav").slideDown(500);
				$('li a.active').removeClass('active');
				$(this).addClass('active');
			}
			return false;
		});
		
		$('a.filter').click(function(){
			var cat = $(this).attr("rel");
			$.cookies.set('thecat', cat);
		});
		
		$('a.filter').click(function() {
			var target = $(this).attr('href');
			$('#wrapper').fadeOut('slow', function() {
				window.location = target;
			});
			return false
		});
			
		slideContent(500, 240, 160);
		
		$(window).resize(function(){
			var _window_w = $(window).width();
			$('#wrapper, #single_entry_container').width(_window_w-30);
		});	
	}
});

function slideContent(h, sTop, oTop){
	var symbol = $('img.port_symbol'),
		symbolH = symbol.height(),
		online = $('img.port_online'),
		onlineH = online.height();
		
	symbol.css("top", (h-symbolH)/2 + "px");	
	symbol.parent().css("height", sTop+symbolH+"px");
	online.css("top", (h-onlineH)/2 + "px");	
	online.parent().css("height", oTop+onlineH+"px");
}