// JavaScript Document
jQuery(document).ready(function($) {
	if( $('#notfound').size() > 0) { $('#notfound').jqm(); $('#notfound').jqmShow(); }
	
	$('.home #InnerContainer li').css('cursor','pointer');
	$('.home #InnerContainer li strong').hide();
	$('.bigpic').hide();
	if( $('.full').size() > 0 ){
		$('#PhotoBox').css('background', 'none');
	}
	var subht = $('#SubMenu').height();
	var subcount = $('#SubMenu li').size();
	var conht = $('.post').height();
	
	$('img.thumbnail').hover(function() {
		var bigID = $(this).attr('id');
		$("."+bigID).show();
	},function() {
		var bigID = $(this).attr('id');
		$("."+bigID).hide();								  
 	});
	
	$('.home #InnerContainer li').hover(function() {
		$(this).find('span').hide();
		$(this).find('a').css('background-position','center top').css('z-index', '500');
		$(this).find('strong').show();
		
	},function() {
		$(this).find('span').show();
		$(this).find('a').css('background-position','center bottom').css('z-index', '1');
		$(this).find('strong').hide();
	});
	$('.home #InnerContainer li').click(function() {
		var goto = $(this).find('a').attr('href');
		window.location.href = goto;
	});
	$("#searchform .submit").click(function(){
			$("#searchform").submit();
	});
	if( $('#dialog').size() > 0 )
		$('#dialog').jqm();
	
/*SCROLLER #1 START*/
$('#scroll-controls').hide();	
if( subht > 428 ){
	$('#scroll-controls').show();
	function getTop() {
		// get the top of the content
		var top = $('#scroll-content').css('top');
		return trimPx(top);
	}
	
	function getHeight(id) {
		// get the height, including padding
		var height = $(id).height();
		var paddingTop = trimPx($(id).css("padding-top"));
		var paddingBottom = trimPx($(id).css("padding-bottom"));
	
		return height + paddingTop + paddingBottom;
	}
	
	function trimPx(value) {
		// remove "px" from values
		var pos = value.indexOf("px");
		if (pos != 0)
			return parseInt(value.substring(0, pos));
		else
			return 0;
	}
	
	var container;
	var content;
	var hidden;	// # of pixels hidden by the container
	
	function setScrollerDimensions() {
		container = getHeight("#scroll-container");
		content = getHeight("#scroll-content");
		hidden = content - container;
	}
	
	function resetScroller() {
		setScrollerDimensions();
		$('#scroll-content').css('top', 0);
	}


	setScrollerDimensions();

	$('#scroll-controls a.up-arrow').click(function() {
		return false;
	});

	$('#scroll-controls a.down-arrow').click(function() {
		return false;
	});

	$('#scroll-controls a.down-arrow').hover(
		function() {
			if (hidden > 0) {
				var current = getTop();
				$('#scroll-content').animate({ top: -hidden }, Math.abs(current - hidden) * 5);
			}
		},
		function() {
			$('#scroll-content').stop();
		}
	);

	$('#scroll-controls a.up-arrow').hover(
		function() {
			if (hidden > 0) {
				var current = getTop();
				$('#scroll-content').animate({ top: "0" }, Math.abs(current) * 5);
			}
		},
		function() {
			$('#scroll-content').stop();
		}
	);
	var AllItems = $('#SubMenu li').size();
	var CurItem = $('#SubMenu li.current_page_item').prevAll().size();
	if( CurItem > 4){
		var less = 0;
		var start = ((CurItem)*54);
		if (CurItem >= (AllItems-6)){
			var less = 6*54;
			var start = ((AllItems)*54)-less;
			//alert(CurItem);
		}
		var current = getTop();
		$('#scroll-content').animate({ top: -start}, Math.abs(current - start) * 5);	
	}
}
/*SCROLLER #1 END*/
//alert(conht);
/*SCROLLER #2 START*/
$('#scroll2-controls').hide();	
if( conht > 360 ){
	$('#scroll2-controls').show();
	function getTop2() {
		// get the top of the content
		var top = $('#scroll2-content').css('top');
		return trimPx2(top);
	}
	
	function getHeight2(id) {
		// get the height, including padding
		var height = $(id).height();
		var paddingTop = trimPx2($(id).css("padding-top"));
		var paddingBottom = trimPx2($(id).css("padding-bottom"));
	
		return height + paddingTop + paddingBottom;
	}
	
	function trimPx2(value) {
		// remove "px" from values
		var pos = value.indexOf("px");
		if (pos != 0)
			return parseInt(value.substring(0, pos));
		else
			return 0;
	}
	
	var container2;
	var content2;
	var hidden2;	// # of pixels hidden by the container
	
	function setScrollerDimensions2() {
		container2 = getHeight2("#scroll2-container");
		content2 = getHeight2("#scroll2-content");
		hidden2 = content2 - container2;
	}
	
	function resetScroller2() {
		setScrollerDimensions2();
		$('#scroll2-content').css('top', 0);
	}


	setScrollerDimensions2();

	$('#scroll2-controls a.up-arrow').click(function() {
		return false;
	});

	$('#scroll2-controls a.down-arrow').click(function() {
		return false;
	});

	$('#scroll2-controls a.down-arrow').hover(
		function() {
			if (hidden2 > 0) {
				var current2 = getTop2();
				$('#scroll2-content').animate({ top: -hidden2 }, Math.abs(current2 - hidden2) * 5);
			}
		},
		function() {
			$('#scroll2-content').stop();
		}
	);

	$('#scroll2-controls a.up-arrow').hover(
		function() {
			if (hidden2 > 0) {
				var current2 = getTop2();
				$('#scroll2-content').animate({ top: "0" }, Math.abs(current2) * 5);
			}
		},
		function() {
			$('#scroll2-content').stop();
		}
	);
}
/*SCROLLER #2 END*/

/* Portfolio Scroller START */
	var isWide = $('.wide').size();
	var isSkinny = $('.skinny').size();
	var Width = 441;
	var Show = 3;
	if( isWide == 1 ){ Width = 600; Show = 4; }
	if( isWide == 1 ){ Width = 300; Show = 2; }
	var PicTotal = $('#MorePhotos img').size();
	var DivWidth = Math.ceil(PicTotal/Show)*Width;
	var Max = DivWidth-Width;
	$x = 0;
	$('#MorePhotos div').css('width', DivWidth+'px');
	if( PicTotal <= Show ){
		$('.prevPics, .nextPics').hide();	
	}
	$('.nextPics').click( function(){
		$x = $x-Width;
		if( $x < -Max ){ $x = 0; }
		$('#MorePhotos div').animate({ marginLeft: $x+'px'}, 1500 );
		return false;
	});
	$('.prevPics').click( function(){
		$x = $x+Width;
		if( $x > 0 ){ $x = -Max; }
		$('#MorePhotos div').animate({ marginLeft: $x+'px'}, 1500 );
		return false;
	});
	
/* Portfolio Scroller END */
	
	var nokeyword = $('#notfound').size();
	if( nokeyword ){
		
	}

});