/*
CSS Browser Selector v0.3.5 (Feb 05, 2010)
Rafael Lima (http://rafael.adm.br)
http://rafael.adm.br/css_browser_selector
License: http://creativecommons.org/licenses/by/2.5/
Contributors: http://rafael.adm.br/css_browser_selector#contributors
*/
function css_browser_selector(u){var ua = u.toLowerCase(),is=function(t){return ua.indexOf(t)>-1;},g='gecko',w='webkit',s='safari',o='opera',h=document.documentElement,b=[(!(/opera|webtv/i.test(ua))&&/msie\s(\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?g+' ff2':is('firefox/3.5')?g+' ff3 ff3_5':is('firefox/3')?g+' ff3':is('gecko/')?g:is('opera')?o+(/version\/(\d+)/.test(ua)?' '+o+RegExp.$1:(/opera(\s|\/)(\d+)/.test(ua)?' '+o+RegExp.$2:'')):is('konqueror')?'konqueror':is('chrome')?w+' chrome':is('iron')?w+' iron':is('applewebkit/')?w+' '+s+(/version\/(\d+)/.test(ua)?' '+s+RegExp.$1:''):is('mozilla/')?g:'',is('j2me')?'mobile':is('iphone')?'iphone':is('ipod')?'ipod':is('mac')?'mac':is('darwin')?'mac':is('webtv')?'webtv':is('win')?'win':is('freebsd')?'freebsd':(is('x11')||is('linux'))?'linux':'','js']; c = b.join(' '); h.className += ' '+c; return c;}; css_browser_selector(navigator.userAgent);

$(document).ready(function() {
	
	var root_url = "http://ravintolanolla.y.neutech.fi/";
	
	// font replacement
	Cufon.replace($("h1, h2, h3, #aside h4, .cufon, ul#navi li a, address"), { fontFamily: 'Benton', hover: true });
	
	//$("body").append('<div class="grad-top">&nbsp;</div><div class="grad-btm">&nbsp;</div>');
	
	function scale() {
		
		var winheight = $(window).height()-100;
		var availwidth = $(window).width()-947;
		var minheight =  winheight-307;
		var gradbtmtop = $(window).height()-50;
		var addrheight =  winheight-195;
		
	    $("#sidebar, #aside-border").attr("style", "height: " + winheight + "px");
	    //$(".grad-btm").attr("style", "top: " + gradbtmtop + "px");
	    $(".minh").attr("style", "min-height: " + minheight + "px");
	    $("#sidebar address").attr("style", "position: absolute; margin-top: 0px; top: " + addrheight + "px");

	    if($(window).height() > 610) {
	    	$(".minhead").attr("style", "min-height: " + winheight/5.8 + "px");
	    } else {
	    	$(".minhead").attr("style", "min-height: 86px");
	    	if($(window).height() < 540) {
	    		$("#sidebar address").hide();
	    	}
	    }
	}
	var resizeTimer = null;
	$(window).bind('resize', function() {
	   if (resizeTimer) clearTimeout(resizeTimer);
	   resizeTimer = setTimeout(scale, 5);
	});
	scale();
	
	// clickable divs etc.
	$(".clickable").click(function() {
    	window.location = $(this).attr("url");
    	return false;
	});
	
	// opacity hover
	$("a.logo, ul.lang a, ul#navi li a, .text p a, .text2 p a, a.unlink, #aside a, .map-overlay, dl.klubit a").hover(function(){
		$(this).stop().fadeTo("fast", 0.65);
	},function(){
   		$(this).stop().fadeTo("fast", 1.0);
	});
	
	$("ul.galleria dt.image a").fancybox({
		'titlePosition'		: 'over',
		'transitionIn'		: 'fade',
		'transitionOut'		: 'fade',
		'autodimension'	: true,
		'overlayOpacity' : '0',
		'padding' : '0',
		'hideOnContentClick' : true,
		'hideOnOverlayClick' : true,
		'transitionIn' : 'fade',
		'transitionOut' : 'fade',
		'centerOnScroll' : 'true'
	});
	
	$("body#home .nosto a").each(function() {
		$(this).parent().attr("url", $(this).attr("href"));
		$(this).remove();
	});
	$("body#home .nosto p").wrapInner("<span />");
	
	/*
	$("body#menu table").addClass("lista");
	$("body#menu table tr td:first-child").addClass("ruoka");
	$("body#menu table tr td:last-child").addClass("hinta").removeAttr("style");
	*/
	
	$("body#blog .tags").each(function() {
		if($(this).children("span").html() != "") {
			$(this).prepend("Tagit "); 
		} else { 
			$(this).remove();
		}
	});
	
	// resize images
	var maxwidth = $("body#blog #content .text2").css('width');
	
	$("body#blog #content .text2 img").each(function() {
		
		if($(this).css("width") > maxwidth) {
			var img = $(this).attr("src").split(root_url);
			$(this).hide().attr("style","").attr("src", "/images/thumb/phpThumb.php?src=/" + img[1] + "&w=482&f=jpg").addClass("png").show();
		}
	});

	
	//$("body#blog .post-separator:last").attr("style","height: 0px");
	$("body#blog #recaptcha_widget_div").toggle();
	$("body#blog #comment_form").bind("click", function(){
		$("body#blog #recaptcha_widget_div").fadeIn();
	});
	
	$("body#blog #recaptcha_response_field").attr("style","border: 1px solid #3c3c3c");
	
	$("body#blog #comment_form").submit(function() {
		
		if ($("input#name").val() == "" || $("input#email").val() == "" || $("textarea#comment").val() == "") {
		   	$('#comment_form .error').html("Ole hyvä ja täytä kaikki tähdellä merkityt kentät.").fadeIn();
		   	return false;
		}
		$('input[type=submit]', this).attr('disabled', 'disabled');
	});

});

// google analytics
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-15336943-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();