// 2011-2 settings
$(document).ready(function(){

	// christmas page flip
	$("#pageflip").hover(function() {
		$("#pageflip a").stop()
			.animate({
				width: '265px', 
				height: '245px'
			}, 1000); 
		$("#pageflip img").stop()
			.animate({
				width: '265px', 
				height: '255px'
			}, 900); 
		} , function() {
		$("#pageflip img").stop() 
			.animate({
				width: '50px', 
				height: '52px'
			}, 550);
		$("#pageflip a").stop() 
			.animate({
				width: '50px', 
				height: '50px'
			}, 500);
	});


	// main menu effects
	$(".lavaLamp").lavaLamp({ fx: "easeOutBack", speed: 700 }); // note backout replaced by easeOutBack in easing v1.3
	$('.lavaLamp li a').addGlow({ textColor: 'white', haloColor: 'white', radius: 20 });
	$('ul#portfolio a, a.feedbacklink, div.details a').addGlow({ textColor: 'white', haloColor: 'white', radius: 15 });
	//$('ul.resourcelist a').addGlow({ textColor: 'white', haloColor: 'red', radius: 5 });
	
	// random background image + stretch to fit
	var bg_imgcount = 14;
	var rand = Math.floor(Math.random()*bg_imgcount) + 1;
	var img_id = (rand < 100 ? '0' : '') + (rand < 10 ? '0' : '') + rand; // http://www.electrictoolbox.com/pad-number-two-digits-javascript/
	//if(jQuery().backstretch) {
		$.backstretch("/new2011-2/images/background-images/" + img_id + ".jpg");
		//alert("images/background-images/" + img_id + ".jpg");
	//}
	
	// content div opacity
	$('#header').css({opacity:0.90});
	$('#content').css({opacity:0.90});
	$('ul#filter li#filterstatus').css({opacity:0.70});

	// sliding door panels
	if(jQuery().mosaic) {
		$('.cover').mosaic({animation:'slide',	hover_x:'341px', speed : 750});	//fade or slide//Horizontal position on hover
	}
	
	// corners
	if(jQuery().corner) {
		$('#filter li a').corner("5px");
		$('#filter li#filterstatus').corner("5px");
		$('ul.resourcelist li a').corner("5px");
	}
	
	// colorbox
	if(jQuery().colorbox) {
		$.fn.colorbox.settings.opacity = 0.7;
		$.fn.colorbox.settings.fixed = false;
		$.fn.colorbox.settings.current = '{current} of {total}';
		$.fn.colorbox.settings.previous = '<img src="/new2011-2/images/cb-previous.png" alt="previous" title="previous" width="31" height="30" />'; // add a graphic
		$.fn.colorbox.settings.next = '<img src="/new2011-2/images/cb-next.png" alt="next" title="next" width="31" height="30" />'; // add a graphic
		$.fn.colorbox.settings.close = '<img src="/new2011-2/images/cb-close.png" alt="close" title="close" width="31" height="30" />'; // add a graphic
		$('#cboxOverlay').css({backgroundColor: '#000'});
		$('#sitesearch').colorbox({width:"800px", height:"600px", iframe:true});
		$('.project').colorbox({innerWidth:"700px;", innerHeight:"520px", iframe:true, rel:'projects', current:'{current} of {total}'});
		$('ul.resourcelist a').colorbox({width:"80%", height:"80%", iframe:true});
		$('ul.contactlist a').colorbox({width:"900px", height:"630px", iframe:true});
		$('.case-study-popup').colorbox({width:"90%", height:"90%", iframe:true});
		$('.legal').colorbox({width:"800px", height:"600px", iframe:true, current:"", rel:"legallinks"});
		
		// christmas
		$('.christmas').colorbox({innerWidth:"1220px", innerHeight:"800px", iframe:true});
	
	}
	
	$('ul.resourcelist a').hover(function(){
		$(this).animate({marginTop:'-5px', marginBottom:'5px'},{queue:false,duration:500});
	}, function(){
		$(this).animate({marginTop:'0px', marginBottom:'0px'},{queue:false,duration:500});
	});
			
	
	if(jQuery().isotope) {
		// add instance count to filter links
		var count_all = $("#portfolio li.all").length;
			$("#all_count").html('('+count_all+')');
		var count_brochure = $("#portfolio li.brochure").length;
			$("#brochure_count").html('('+count_brochure+')');
		var count_dynamic = $("#portfolio li.dynamic").length;
			$("#dynamic_count").html('('+count_dynamic+')');
		var count_ecommerce = $("#portfolio li.ecommerce").length;
			$("#ecommerce_count").html('('+count_ecommerce+')');
		var count_redesign = $("#portfolio li.redesign").length;
			$("#redesign_count").html('('+count_redesign+')');
		var count_database = $("#portfolio li.database").length;
			$("#database_count").html('('+count_database+')');
		var count_logo = $("#portfolio li.logo").length;
			$("#logo_count").html('('+count_logo+')');
		var count_business = $("#portfolio li.business").length;
			$("#business_count").html('('+count_business+')');
		var count_charity = $("#portfolio li.charity").length;
			$("#charity_count").html('('+count_charity+')');
		var count_public = $("#portfolio li.public").length;
			$("#public_count").html('('+count_public+')');
		var count_support = $("#portfolio li.support").length;
			$("#support_count").html('('+count_support+')');

		$('.bluelist, .greenlist, .redlist, .whitelist').isotope('reLayout');
		
		// cache container
		var $isocontainer = $('#portfolio');

		// isotope settings (originally controlled via css
		// HOW???????????????????

		// initialize isotope
		$isocontainer.isotope({  
			transformsEnabled: true,
			resizesContainer: true
		});


		$('ul#filter a').click(function(e) {
			$('#filterstatus').animate({ width: "hide"}, 100);
			$(this).css('outline','none');
			$('ul#filter .current').removeClass('current');  
			$(this).parent().addClass('current');
			var selector = '.'+$(this).attr('href').replace(/#/g,'');
			$isocontainer.isotope({ filter: selector, itemSelector : '.all' });
			$('#filterstatus').animate({ width: "show"}, 1000).html($(this).attr('title').replace("Show ", ""));
			$('#footer').positionFooter();
			return false;
		});
		//$('ul#filter a:first').click();
	}

	// portfolio hover effect from: http://davidwalsh.name/dw-content/fade-except-jquery.php
	var focus_op = 1.0;
	var fade_op = 0.5
	$('ul#portfolio').children().hover(function() {
		$(this).siblings().stop().fadeTo(100,fade_op);
	}, function() {
		$(this).siblings().stop().fadeTo(100,focus_op);
	});


});
$(window).ready(function(){

	$('#footer').positionFooter();
	$('#footer').css({opacity:0.75});
	$(window).resize(function() {$('#footer').positionFooter();});
	//$(window).scroll(function() {$('#footer').positionFooter();});

});

