// OFF THE CUFF StartUp JavaScript Document

// Startup settings for site - edited by P Dance Feb 2011

$(document).ready(function() {
			//RESIZEMARG
			//sets sliding area margins depending on view port width - only if the screen is larger than 980px;
			//called on page load and windows resize
			
			
			function resizeMarg() {
	
				var winWidth = $(window).width();
				var divmarg = (winWidth - 980)/2;
				if (divmarg > 0){
					$('div.panelContent').attr('style', 'margin-left:'+divmarg+'px');
				}
				if (divmarg < 0){
					$('div.panelContent').attr('style', 'margin-left:0px');
				}
				fadeIn();
			};
			
			setTimeout(function() {resizeMarg(); }, 700);
			function fadeIn(){$(".panelContent").fadeIn("slow");}
			
			$(window).resize(function() {resizeMarg()});
			$('.blinker').innerfade({
				animationtype: 'fade',
				speed: 750,
				timeout: 0,
				type: 'sequence',
				containerheight: '1em'
			});
			
			//Image blinker
			// Bind a custom event to your image object

			
			$("img.blnk").bind("fadeToggle", function() {
			
				// Negate the current value of the fadeIn object in this element's data store
				// Initial fire will set value to !null (which == true)
				$(this).data("fadeIn", !$(this).data("fadeIn"));
			
				// Create a callback function to recursively trigger the event at the end of either animation
				var callback = function() {
					$(this).trigger("fadeToggle");
				};
			
				// Test the value in the data store
				if ($(this).data("fadeIn")) {
			
					// Fade in and trigger the next fadeToggle event
					$(this).fadeIn("slow", callback);
				} else {
			
					// Fade out and trigger the next fadeToggle event
					$(this).fadeOut("slow", callback);
				}
			}).trigger("fadeToggle"); // Trigger first event to start the chain
						
			
			
			
			
		//Overlay setup for home page link	
		$("#inline").fancybox();
		$("a.iframe").fancybox({
		'hideOnContentClick': true,
		'width':720,
		'height':500
		});

		
		
		
		//Target_blank replacemnt to satisfy XHTML strict compliance
		function externalLinks() {   
		 if (!document.getElementsByTagName) return;   
		 var anchors = document.getElementsByTagName("a");   
		 for (var i=0; i<anchors.length; i++) {   
		   var anchor = anchors[i];   
		   if (anchor.getAttribute("href") &&   
			   anchor.getAttribute("rel") == "external")   
			 anchor.target = "_blank";   
		 }   
		}   
		window.onload = externalLinks;
		
		
		
		//Portfolio Setup
		$('ul#filter a').click(function() {
		$(this).css('outline','none');
		$('ul#filter .current').removeClass('current');
		$(this).parent().addClass('current');
		
		var filterVal = $(this).attr("title").toLowerCase().replace(' ','-');
				
		if(filterVal == 'all') {
			$('ul#portfolioList li.hidden').fadeIn('slow').removeClass('hidden');
		} else {
			
			$('ul#portfolioList li').each(function() {
				if(!$(this).hasClass(filterVal)) {
					$(this).fadeOut('normal').addClass('hidden');
				} else {
					$(this).fadeIn('slow').removeClass('hidden');
				}
			});
		}
		
		return false;
	});

			
			
			
			
});
			
