/*
CSS Browser Selector v0.2.7
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
*/

var css_browser_selector = function() {var ua=navigator.userAgent.toLowerCase(),is=function(t){return ua.indexOf(t) != -1;},h=document.getElementsByTagName('html')[0],b=(!(/opera|webtv/i.test(ua))&&/msie (\d)/.test(ua))?('ie ie'+RegExp.$1):is('firefox/2')?'gecko ff2':is('firefox/3')?'gecko ff3':is('gecko/')?'gecko':is('opera/9')?'opera opera9':/opera (\d)/.test(ua)?'opera opera'+RegExp.$1:is('konqueror')?'konqueror':is('applewebkit/')?'webkit safari':is('mozilla/')?'gecko':'',os=(is('x11')||is('linux'))?' linux':is('mac')?' mac':is('win')?' win':'';var c=b+os+' js'; h.className += h.className?' '+c:c;}();


$(document).ready(function() {
	
	// string replace 
	function str_replace_reg(haystack, needle, replacement) {
		var r = new RegExp(needle, 'g');
		return haystack.replace(r, replacement);
	}
	
	// anti-spam email
	$('span.email').each(function()
	{
	    var obfAddress = $(this).text();
	    var realAddress = obfAddress.replace(/\[at\]/g, '@').replace(/\[dot\]/g, '.');
	    var emailLink = document.createElement('a');
	    $(emailLink).attr(
	    {
	        'href': 'mailto:' + realAddress,
	        'title': 'Email: ' + realAddress,
	        'class': 'email-address'
	    }).text(realAddress);
	    $(this).replaceWith(emailLink);
	});
	
	// clear searchfield default text on focus
	$.fn.clearInput = function() 
	{
		return this.focus(function() 
		{
			if( this.value == this.defaultValue ) 
			{
				this.value = "";
			}
		}).blur(function() 
		{
			if( !this.value.length ) 
			{
				this.value = this.defaultValue;
			}
		});
		
	};
	$("input#mlist").clearInput();
	
	// toggler
	$.fn.toggler = function(div) {
		$(div).slideToggle('fast');
		return false;
	};
	
	var root_url = "http://www.bionature.fi/";
	
	// enlarge thumbnails
	$('.image-wrapper img').each(function()
	{
	    var txt = $(this).text();
	    var link = document.createElement('a');
	    var imgUrl = $(this).attr("src");
	    var repUrl = str_replace_reg(imgUrl, "_thumb", "");
	    $(this).wrap('<a href="' + repUrl + '"></a>');
	});
	$('.image-wrapper a').each(function()
	{
	    $(this).attr("alt", "Klikkaa isommaksi");
	});
	if($(".image-wrapper a").length) {
		$(".image-wrapper a").fancybox();
	}
	
	$("#content div.thumb-sticky img").each(function() {
		
		var im = $(this).attr("src").split(root_url);
		if(im[1] == undefined) var im = $(this).attr("src").split("http://bionature.fi/");
		var img = im[1];
		var im_position = "C";
		
		$(this).removeAttr("width").removeAttr("height").attr("src", root_url + "images/thumb/phpThumb.php?src=/" + img + "&w=621&h=350&wp=450&h=621&hp=450&hl=450&hs=450&f=png").addClass("png").wrap('<span class="thumb-wrap"></span>');
		$(this).parents("div.thumb").css("height:" + $(this).height() + "px");
	});
	
	$("#content div.thumb img").each(function() {
		
		var im = $(this).attr("src").split(root_url);
		if(im[1] == undefined) var im = $(this).attr("src").split("http://bionature.fi/");
		var img = im[1];
		var im_position = "C";
		
		$(this).removeAttr("width").removeAttr("height").attr("src", root_url + "images/thumb/phpThumb.php?src=/" + img + "&w=310&h=220&wp=150&h=220&hp=220&hl=220&hs=220&f=png").addClass("png").wrap('<span class="thumb-wrap"></span>');
		$(this).parents("div.thumb").css("height:" + $(this).height() + "px");
	});
	
	$("body#cdo ul#nav_categories li ul li:first").addClass("sub");
	
	/*
	$("#content div.thumb").each(function() {
		$(this).append('<img src="images/thumb/shadow.png" class="thumb-shadow" class="png" height="30" alt="" />');
	});
	*/
	//$("div#content p img.right").wrap("<div style='overflow: hidden; display: block' class='span-2 right rounded'></div>");
	
	
	
	if($("#slideshow").length || $("#slideshow2").length) {
		// cycle plugin options
		$.fn.cycle.defaults.speed   = 900;
		$.fn.cycle.defaults.timeout = 6000;
	}
	$("body#cc li.sub li:last-child").addClass("sub hoidot");
	
});


