/******************************************************
*
*	Softscroll
*
******************************************************/
$(document).ready(function(){
$('a[href*=#]').click(function() {
	if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
	&& location.hostname == this.hostname) {
		var $target = $(this.hash);
		$target = $target.length && $target
		|| $('[name=' + this.hash.slice(1) +']');
		if ($target.length) {
			var targetOffset = $target.offset().top;
			$('html,body')
			.animate({scrollTop: targetOffset}, 1000);
			return false;
		}
	}
});
});



/******************************************************
*
*	Image preloader
*
******************************************************/
$(function() {
	$('.slide img').hide();
	$('.slide').addClass('loading');
});

var i = 0;
var int=0;
$(window).bind("load", function() {
	var int = setInterval("doThis(i)",500);
});

function doThis() {
	var imgs = $('img').length;
	if (i >= imgs) {
		clearInterval(int);
	}
	$('img:hidden').eq(0).fadeIn(500);
	i++;
	
	$('.slide').removeClass('loading');
	$('.slide img').show();
}

	

/******************************************************
*
*	Default value on search box and contact form
*
******************************************************/
$(function() {
    $('#search input[type=text], #emailus input[type=text]').addClass("onBlur");
	$('#search input[type=text], #emailus input[type=text]').focus(function() {
		$(this).removeClass("onBlur");
        if (this.value == this.defaultValue){
        	this.value = '';
    	}
        if(this.value != this.defaultValue){
	    	this.select();
        }
    });
    $('#search input[type=text], #emailus input[type=text]').blur(function() {
        if (this.value == ''){
			$(this).addClass("onBlur");
        	this.value = (this.defaultValue ? this.defaultValue : '');
    	}
    });
});



/******************************************************
*
*	Initialize scrolldown menu
*
******************************************************/
$(function() {
	jQuery('#foldermenu ul').superfish({
		delay:       0,                            // one second delay on mouseout 
		animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
		speed:       'fast',                          // faster animation speed 
		autoArrows:  false,                           // disable generation of arrow mark-up 
		dropShadows: false                            // disable drop shadows 
	});
});

$(function() {
	jQuery('#flatmenu ul').superfish({
		delay:       0,                            // one second delay on mouseout 
		animation:   {opacity:'show',height:'show'},  // fade-in and slide-down animation 
		speed:       'fast',                          // faster animation speed 
		autoArrows:  false,                           // disable generation of arrow mark-up 
		dropShadows: false                            // disable drop shadows 
	});
});

	

/******************************************************
*
*	Rounded corner on submenu and border
*
******************************************************/
$(function() {
	$('#foldermenu ul').find('li:last').addClass("last");
	$('#foldermenu ul').find('li:first').addClass("first");
	$('.foldermenu li:first').before('<li class="beforeUl">&nbsp;</li>');
	$('.foldermenu li:visible:last').after('<li class="afterUl">&nbsp;</li>');
	$('#flatmenu ul').find('li:last').addClass("last");
	$('#flatmenu ul').find('li:first').addClass("first");
});

$(function() {
    $('#flatmenu a').hover(
	function() { 
        $(this).parent().addClass('flat_hover');
	},
	function() { 
        $(this).parent().removeClass('flat_hover');
	});
});

$(function() {
    $('#flatmenu li ul').hover(
	function() { 
        $(this).parent().addClass('flat_hover');
        $(this).parent().find('a').addClass('hover');
	},
	function() { 
        $(this).parent().removeClass('flat_hover');
        $(this).parent().find('a').removeClass('hover');
	});
});

	
	
	
/******************************************************
*
*	Home page slideshow
*
******************************************************/

$(function() {
	if ($('#slideshow').length != 0) {
		$('#slideshow .slide').cycle({
		fx:'fade',
		speed:1000,
		timeout:7000,
		cleartype:!$.support.opacity,
		cleartypeNoBg:true,
		prev:'#slideshow #prev', 
		next:'#slideshow #next',
		pauseOnPagerHover:true, 
		pause:1,
		pager:'#nav',
		pagerAnchorBuilder: function(idx, slide) {
		return '<a href="#">&nbsp;</a>';
        }
		});
	}
});
$(function() {
    $('#slideshow .slide').hover(
	function() { 
        $(this).find('.innercaption').animate({opacity:1, marginTop:'-15'}, 200);
	},
	function() { 
        $(this).find('.innercaption').animate({opacity:0, marginTop:'0'}, 200);
	});
});
	
	
/******************************************************
*
*	Background effect on mouse over
*
******************************************************/
$(function() {
	$('#prev')
		.css( {backgroundPosition: "12px 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(12px 0)"}, {duration:100, complete:function(){
				$(this).css({backgroundPosition: "12px 0"})
			}})
		})
	$('#next')
		.css( {backgroundPosition: "-12px 0"} )
		.mouseover(function(){
			$(this).stop().animate({backgroundPosition:"(0 0)"}, {duration:100})
		})
		.mouseout(function(){
			$(this).stop().animate({backgroundPosition:"(-12px 0)"}, {duration:100, complete:function(){
				$(this).css({backgroundPosition: "-12px 0"})
			}})
		})
});



/******************************************************
*
*	Rounded corner on sidebar
*
******************************************************/
$(function() {
	$('.sidebar > .inner').before('<div class="topsidebar"></div>');
	$('.sidebar > .inner').after('<div class="bottomsidebar"></div>');
});
	


/******************************************************
*
*	Sidebar links border
*
******************************************************/
$(function() {
	$('.sidebar > .inner').find('li:first').css({'border-top':'none', 'padding-top':0});
	$('.sidebar > .inner li ul').find('li:first').css({'border-top':'1px solid #fff', 'padding-top':'8px'});
});
	


/******************************************************
*
*	Rounded corner on innerdouble
*
******************************************************/
$(function() {
	$('.innerdouble').before('<div class="topdouble"></div>');
	$('.innerdouble').after('<div class="bottomdouble"></div>');
});
	


/******************************************************
*
*	Click effect on entry div
*
******************************************************/
$(function() {
	$('.widget_apogeoslidingnews .entry').hover( 
function() {
			$('.widget_apogeoslidingnews').addClass('hover');
		},
		function() {
			$('.widget_apogeoslidingnews').removeClass('hover');
		}
	);
	$('.widget_apogeoslidingnews .entry').click( 
function() {
			var href = $(this).find('.more').attr('href');
			window.location = href;
		}
	);
});

	

/******************************************************
*
*	Hover and click effect on thirdpart div
*
******************************************************/
$(function() {
	$('#teasers .thirdpart').hover( 
function() {
			$(this).addClass('hover');
		},
		function() {
			$(this).removeClass('hover');
		}
	);
	$('#teasers .thirdpart').click( 
function() {
			var href = $(this).find('.more').attr('href');
			window.location = href;
		}
	);
});
	
	
	
/******************************************************
*
*	Equal height of teasers
*
******************************************************/
function equalHeight(group) {
	var tallest = 0;
	group.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}
$(window).load(function() {
	equalHeight($("#teasers .thirdpart .inner"));
});



/******************************************************
*
*	News sidebar slideshow
*
******************************************************/

$(function() {
	if ($('.widget_apogeoslidingnews .slidenews').length != 0) {
		$('.widget_apogeoslidingnews .slidenews').cycle({
		fx:'fade',
		speed:500,
		timeout:7000,
		cleartype:!$.support.opacity,
		cleartypeNoBg:true,
		prev:'.widget_apogeoslidingnews .prev', 
		next:'.widget_apogeoslidingnews .next'
		});
	}
});
	
	
	
/******************************************************
*
*	Comments sidebar slideshow
*
******************************************************/

$(function() {
	if ($('.apogeo-recent-comments ul').length != 0) {
		$('.apogeo-recent-comments ul').cycle({
		fx:'fade',
		speed:500,
		timeout:7000,
		cleartype:!$.support.opacity,
		cleartypeNoBg:true,
		prev:'.apogeo-recent-comments .prev', 
		next:'.apogeo-recent-comments .next'
		});
	}
});
	
	
	
/******************************************************
*
*	Rounded corner on quicklinks
*
******************************************************/
$(function() {
	$('#quicklinks').before('<div id="topquicklinks"></div>');
	$('#quicklinks').after('<div id="bottomquicklinks"></div>');
});



/******************************************************
*
*	Credits position
*
******************************************************/
$(function() {
	if ($('#logosmall').length != 0) {
		var credW = ($('#credits .credits').width())*0.5;
		var backW = $('#credits #backtotop').width();
		var margL = (500 - (credW + backW) + "px");
		$('#credits .credits').css('margin-left', margL);
	}
	else {
		$('#credits .credits').css('margin-left', 0);
	}
});



/******************************************************
*
*	Menu position
*
******************************************************/
$(function() {
	var laSize = $('.foldermenu a:visible').size();
	var menuW = $('.foldermenu').width();
	var allPaddings = (950-menuW)*0.5;
	var aPadding = allPaddings/laSize;
	if (aPadding>100) {
		var aPadding = 100;
	}
	$('.foldermenu a:visible').css('padding-left', aPadding);
	$('.foldermenu a:visible').css('padding-right', aPadding);
	var menuW2 = ($('.foldermenu').width())*0.5;
	var menuL = (480 - (menuW2) + "px");
	$('.foldermenu').css('margin-left', menuL);
	$('.foldermenu').css('visibility', 'visible');
});



/******************************************************
*
*	Home page feature 
*
******************************************************/
$(function() {
var newText = $("#linetotal").text().split("|").join("</div><div class=\"vegur\" style=\"padding-left:90px;display:inline;float:left;\">");
newText = "<div class=\"leftquote\"></div><div class=\"vegur\" style=\"display:inline;float:left;\">" + newText + "<div class=\"rightquote\"></div></div>";
$("#linerender").html(newText);

});



/******************************************************
*
*	Color box in general
*
******************************************************/
$(document).ready(function(){
	$("a[rel='iframe']").colorbox({iframe:true, innerWidth:650, innerHeight:488, rel:'nofollow'});
	$("a#map[rel='iframe']").colorbox({iframe:true, innerWidth:800, innerHeight:600, rel:'nofollow'});
	var the_src = $("#hidemap iframe").attr('src');
	var v = the_src.replace(/\\"/g,'');
	$("a#map[rel='iframe']").attr("href", v);
});


$(document).ready(function(){
	$(".post .entry a[href$='.jpg']").colorbox({maxWidth:"98%", maxHeight:"98%"});
	$(".post .entry a[href$='.png']").colorbox({maxWidth:"98%", maxHeight:"98%"});
	$(".post .entry a[href$='.jpg']").colorbox({maxWidth:"98%", maxHeight:"98%"});
	$(".showcase a[href$='.jpg']").colorbox({maxWidth:"98%", maxHeight:"98%"});
	$(".showcase a[href$='.png']").colorbox({maxWidth:"98%", maxHeight:"98%"});
	$(".showcase a[href$='.jpg']").colorbox({maxWidth:"98%", maxHeight:"98%"});
	$(".widget_apogeothumbgallery a[href$='.jpg']").colorbox({maxWidth:"98%", maxHeight:"98%"});
	$(".widget_apogeothumbgallery a[href$='.png']").colorbox({maxWidth:"98%", maxHeight:"98%"});
	$(".widget_apogeothumbgallery a[href$='.jpg']").colorbox({maxWidth:"98%", maxHeight:"98%"});
});



/******************************************************
*
*	Gallery image captions 
*
******************************************************/
$(document).ready(function(){
	$('.boxgrid.captionfull').hover(function(){
		var captionheight = $(this).find(".boxcaption .captionheight").height();
		
		$(".cover", this).stop().animate({top:captionheight,opacity:0},250,function(){$(this).css('display','none');});
	}, function() {
		$(".cover", this).stop().css('display','block').animate({top:'0px',opacity:1},250);
	});
});




/******************************************************
*
*	Emailus inputs widths 
*
******************************************************/
$(document).ready(function(){
	var lab_name_w = $('#emailus #lab_name').width();
	var lab_mail_w = $('#emailus #lab_mail').width();
	if(lab_name_w<260){
		var fst_input = ((476-lab_name_w)*0.5)-15;
	}
	else {
		var fst_input = (476*0.5)-15;
		$('#emailus #firstname').css('margin-left',0);
	}
	if(lab_name_w<260){
		var lst_input = (476-lab_mail_w)-15;
	}
	else {
		var lst_input = 470;
		$('#emailus #email').css('margin-left',0);
	}
	$('#emailus #firstname').css('width',fst_input);
	$('#emailus #lastname').css('width',fst_input);
	$('#emailus #email').css('width',lst_input);
	
});

