/**
 * scripts for pactum.design
 */

$(document).ready(function()
{
	/* content min-height for footer */
	var html = document.documentElement;
	var baseContentHeight = $('#content').height();
	var newContentHeight = html.clientHeight-500;
	$('#content').css({'min-height': newContentHeight+'px'});
	/* content min-height for IE6 */
	if ($.browser.msie && parseInt($.browser.version) <= 6) {
		if ( baseContentHeight < newContentHeight ) {
			$('#content').css({'height': newContentHeight+'px'});
		}
	}
	
	/* start Resize */
	var resizeTimer = null;
	var $partnerIcon = $('.partners:first');
	var cut = '<div class="clear"></div>';
	var minWidthItem = 230;
	var $item = $('.partner');
	
	function portfolioRepaint() {
		var contentWidth = $('#partners').width();
		var items_count = Math.floor(contentWidth/minWidthItem);
		
		var newWidth = 100/items_count;
		newWidth = parseInt(newWidth);
		
		$item.css('width',(newWidth-0.30)+'%');			
		$item.each(function(count){
			if( count > items_count*2-1) $(this).hide();
				else $(this).show();
		});
		//$item.eq(items_count).after(cut);		
	};
	
	$(function(){
		portfolioRepaint();
	});
	
	$(window).bind('resize', function() {
		if (resizeTimer) clearTimeout(resizeTimer);
		resizeTimer = setTimeout(portfolioRepaint, 50);
	});
	/* end Resize*/
	
	/* start shark animate */
	var clickOn = true;
	$('#shark').sprite({fps: 3, no_of_frames: 3});
	$('#shark').click(function(){
		if( clickOn == false ) return;
		clickOn = false;
		$('#shark').fps(8);
		var windowWidth = $(window).width();
		$(this).animate(
			{'left':windowWidth+'px'},{ 
				duration: 8000, 
				easing: 'easeInOutCirc',
				complete:function() {
					$(this).css('left',-50+'px');
				}
			}
		).animate(
			{'left':5+'px'},{ 
				duration: 400, 
				easing: 'swing',
				complete:function() {
					clickOn = true;
					$('#shark').fps(3);
				}						
			}
		);		
		return false;
	});
	/* end shark animate */

	
});
