/* <![CDATA[ */
$(document).ready(function(){
	//var starttime = new Date().getTime();
						   
	//nivo slider settings
	var header = $('#header');
	var slider = $('#slider');
	slider.nivoSlider({
		effect:'sliceUpDown',
		slices: 12,
		animSpeed: 800,
		pauseTime: 8000,
		directionNav:true,
		directionNavHide:true,
		controlNav:true,
		pauseOnHover:true,
		manualAdvance:false,
		captionOpacity: 0.7,
		beforeChange: function(){},
		afterChange: function(){}
	});
	
	//slider hide & show
	var sliderarrow = $('#slider_arrow');
		sliderarrow.click(function(){
		if ($(this).hasClass('arrow_up')) {
			slider.animate({
				opacity: 0
			}, 1000 );
			header.animate({ 
				height: '80'
			}, 1000, function(){
				sliderarrow.removeClass("arrow_up").addClass("arrow_down");
			});
		} else {
			slider.animate({
				opacity: 1
			}, 1000 );
			header.animate({ 
				height: '400'
			}, 1000, function(){
				sliderarrow.removeClass("arrow_down").addClass("arrow_up");
			});
		}
	});
	sliderarrow.hover(
		function () {
			$(this).animate({
				top: "-12px"
			}, 100 );
	  	},
	  	function () {
			$(this).animate({
				top: "-10px"
			}, 100 );
	  	}
	);
	
	//fixes the active childpage
	$('#mainmenu .menu ul li.has_submenu ul li.current_page_item').parent().parent().addClass("current_page_item");

	//font replacement & text shadows
	$('h1,.menu ul li a,#slider .nivo-caption p').addClass("junction");
	//Cufon.replace('#tagline p',{ fontFamily: 'OFL Sorts Mill Goudy TT' });
	
	//Cufon.replace('#sidebar .junction, #content .post .junction, #card-container .junction',{ fontFamily: 'Junction', textShadow: '#fff 0px 1px' });
	//Cufon.replace('#footer .junction',{ fontFamily: 'Junction', textShadow: '#000 0px -1px' });
	//Cufon.replace('#content .title-container .junction, #mainmenu ul li:not(.current_page_item) a.junction',{ fontFamily: 'Junction', textShadow: '#444 0px -1px' });
	//Cufon.replace('#mainmenu ul li.current_page_item a.junction',{ fontFamily: 'Junction', textShadow: '#fff 0px -1px' });
	
	//$('.frontcontent p, .post-content, #sidebar .sidepanel, .topleft-meta, .topright-meta, #breadcrumbs, #card-container').addClass("text-shadow-white");
	//$('#footer .sidepanel').addClass("text-shadow-black");
	//$('.readmore, input[type="submit"]').addClass("text-shadow-black-indent");
	
	//fixing menu hovers as cufon can't seem to handle different div-hover colors
	/*$('#mainmenu .menu ul li.parent_page:not(.current_page_item)').hover(
		function () {
			Cufon.replace($('a.junction',$(this)),{ fontFamily: 'Junction', color: '#c10000', textShadow: '#fff 0px -1px' });
	  	},
	  	function () {
			Cufon.replace($('a.junction',$(this)),{ fontFamily: 'Junction', color: '#fff', textShadow: '#444 0px -1px' });
	  	}
	);*/

	//button hover effect
	var content = $('#content')
	$(".readmore, input[type='submit']").hover(
		function () {
			$(this).animate({
				opacity: 0.8
			}, 100 );
	  	},
	  	function () {
			$(this).animate({
				opacity: 1
			}, 100 );
	  	}
	);
	
	$('#fronttext-devider1,#fronttext-devider2').css('height',content.height()-40);
	
	//menu card
	window.cardcontainer = $('#card-container');
	window.cardnext = $('#card-next');
	window.cardprev = $('#card-prev');
	window.activepage = cardcontainer.attr('activepage');
	cardcontainer.animate({
		height: $('#cardpageid-' + window.activepage).height()
	}, 500 );
	if (window.activepage == 1) {
		cardprev.fadeOut(0);
	}
	var marginLeft = ((window.activepage-1)*956)*-1;
	$('#card-slider').css("left",marginLeft);
	window.totalPages = $('.card-page').size();
	if (window.activepage == window.totalPages){
		window.cardnext.fadeOut(0);
	}
	window.blockAnimation = false;
	$('#card-next, #card-prev').click(function(){
		direction = $(this).attr('id')
		if ( direction == 'card-next' ){
			cardNavigation(false)
		} else {
			cardNavigation(true)
		}
		return false
	});
	cardprev.hover(
		function () {
			$(this).animate({
				left: "-10px"
			}, 100 );
	  	},
	  	function () {
			$(this).animate({
				left: "-8px"
			}, 100 );
	  	}
	);
	cardnext.hover(
		function () {
			$(this).animate({
				right: "-10px"
			}, 100 );
	  	},
	  	function () {
			$(this).animate({
				right: "-8px"
			}, 100 );
	  	}
	);
	
	//var elapsed = new Date().getTime() - starttime;
	//alert('Time elapsed: ' + elapsed + ' milliseconds');
});

function cardNavigation(prev){
	marginLeft = ((window.activepage-1)*956)*-1;
	if (window.blockAnimation == false) {
		window.blockAnimation = true;
		if ( prev == true ){
			window.activepage--;
		} else {
			window.activepage++;
		}
		if (window.activepage == window.totalPages){
			window.cardnext.fadeOut(500);
		}
		if (window.activepage == (window.totalPages-1)){
			window.cardnext.fadeIn(500);
		}
		if (window.activepage == 1){
			window.cardprev.fadeOut(500);
		}
		if (window.activepage == 2){
			window.cardprev.fadeIn(500);
		}
		window.cardcontainer.attr('activepage', window.activepage).animate({
			height: $('#cardpageid-' + window.activepage).height()
		}, 1000 );
		
		left = ( prev == true ) ? (marginLeft + 956) : (marginLeft - 956)
		
		$('#card-slider').animate({
			left: left
		}, 1000, function(){
			window.blockAnimation = false;
		});
	}
}
/* ]]> */
