// Helsinki-kirjat scripts

var menutop = 0;

jQuery(document).ready(function(){
	if (!navigator.userAgent.match(/like Mac OS X/i) && !((jQuery.browser.msie) && parseInt(jQuery.browser.version, 10) < 8)) { // do not do this for IOS or old explorer
		
		// save main menu location
		menutop = jQuery('#mainnavigation').offset().top;
		// Tie menu location to scroll position
		jQuery(window).scroll(function(e){ 
			$el = jQuery('#mainnavigation'); 
			if (jQuery(this).scrollTop() >= menutop && $el.css('position') != 'fixed') { 
				jQuery('#mainnavigation').css('position','fixed');
				jQuery('#mainnavigation').css('top','0px');
				jQuery('#mainnavigation').css('left','50%');
				jQuery('#mainnavigation').css('margin','0 0 0 -465px');
			} else if (jQuery(this).scrollTop() < menutop && $el.css('position') != 'absolute') {
				jQuery('#mainnavigation').css('position','absolute');
				jQuery('#mainnavigation').css('top', menutop + 'px');
			} 
		});
		
    }
	
	
	// Match headings when needed
	if (jQuery('.matchheadings').length != 0) {
		// Get heading heights
		headingheight = 0;
		jQuery('.matchheadings .post-title').each(function(){
			if (jQuery(this).height() > headingheight) {
				headingheight = jQuery(this).height();
			}
		});
		jQuery('.matchheadings .post-title').each(function(){
			paddingtoadd = (headingheight-jQuery(this).height()) + 'px';
			jQuery(this).css('padding-top',paddingtoadd);
		});
	}
	 
	// Stretch bordered columns to full parent height
	jQuery('.bordered').each(function(){
		jQuery(this).height(jQuery(this).parent('.multicol').height());
	});
});


function mailme(name,domain,subj) {
	if (subj == undefined) subj = ""; 
	lctn = 'mailto:' + name + '@' + domain + '?subject=' + subj;
	document.location = lctn;
}

