//functions

//Email protection
$(document).ready(function(){
	$('a.email').each(function(){
		e = this.rel.replace('/','@');
		this.href = 'mailto:' + e;
		$(this).text(e);
	});
});





/*
 * jNice by Sean Mooney (sean@whitespace-creative.com)
 * UPDATED: 12.19.07
*/
(function($){
	$.fn.ssForm = function(options){
		var self = this;
		var safari = $.browser.safari; /* We need to check for safari to fix the input:text problem */	
		/* each form */
		this.each(function(){
			/***************************
			  Buttons
			 ***************************/
			var setButton = function(){
				$(this).replaceWith('<button id="'+ this.id +'" name="'+ this.name +'" type="'+ this.type +'" class="'+ this.className +'"><span><span>'+ $(this).attr('value') +'</span></span>');
			};
			$('input:submit, input:reset', this).each(setButton);			
			/***************************
			  Text Fields 
			 ***************************/
			var setText = function(){
				var $input = $(this);
				$input.addClass("ssFormInput").wrap('<div class="ssFormInputWrapper"><div class="ssFormInputInner"><div></div></div></div>');
				var $wrapper = $input.parents('div.ssFormInputWrapper');
				//$wrapper.css("width", $(this).width()+10);
				$input.focus(function(){
					$wrapper.addClass("ssFormInputWrapper_hover");
				}).blur(function(){
					$wrapper.removeClass("ssFormInputWrapper_hover");
				});
			};
			$('input:text:visible, input:password', this).each(setText);
			/* If this is safari we need to add an extra class */
			if (safari){$('.ssFormInputWrapper').each(function(){$(this).addClass('ssFormSafari').find('input').css('width', $(this).width()+11);});}		
			/***************************
			  Check Boxes 
			 ***************************/
			$('input:checkbox', this).each(function(){
				$(this).addClass('ssFormHidden').wrap('<span></span>');
				var $wrapper = $(this).parent();
				$wrapper.prepend('<a href="#" class="ssFormCheckbox"></a>');
				/* Click Handler */
				$(this).siblings('a.ssFormCheckbox').click(function(){
						var $a = $(this);
						var input = $a.siblings('input')[0];
						if (input.checked===true){
							input.checked = false;
							$a.removeClass('ssFormChecked');
						}
						else {
							input.checked = true;
							$a.addClass('ssFormChecked');
						}
						return false;
				});
				/* set the default state */
				if (this.checked){$('a.ssFormCheckbox', $wrapper).addClass('ssFormChecked');}
			});			
			/***************************
			  Radios 
			 ***************************/
			$('input:radio', this).each(function(){
				$input = $(this);
				$input.addClass('ssFormHidden').wrap('<span class="jRadioWrapper"></span>');
				var $wrapper = $input.parent();
				$wrapper.prepend('<a href="#" class="ssFormRadio" rel="'+ this.name +'"></a>');
				/* Click Handler */
				$('a.ssFormRadio', $wrapper).click(function(){
						var $a = $(this);
						$a.siblings('input')[0].checked = true;
						$a.addClass('ssFormChecked');
						/* uncheck all others of same name */
						$('a[rel="'+ $a.attr('rel') +'"]').not($a).each(function(){
							$(this).removeClass('ssFormChecked').siblings('input')[0].checked=false;
						});
						return false;
				});
				/* set the default state */
				if (this.checked){$('a.ssFormRadio', $wrapper).addClass('ssFormChecked');}
			});		
			/***************************
			  Selects 
			 ***************************/
			$('select', this).each(function(index){
				var $select = $(this);
				/* First thing we do is Wrap it */
				$(this).addClass('ssFormHidden').wrap('<div class="ssFormSelectWrapper"></div>');
				var $wrapper = $(this).parent().css({zIndex: 100-index});
				/* Now add the html for the select */
				$wrapper.prepend('<div><span></span><a href="#" class="ssFormSelectOpen"></a></div><ul></ul>');
				var $ul = $('ul', $wrapper);
				/* Now we add the options */
				$('option', this).each(function(i){
					$ul.append('<li><a href="#" index="'+ i +'">'+ this.text +'</a></li>');
				});
				/* Hide the ul and add click handler to the a */
				$ul.hide().find('a').click(function(){
						$('a.selected', $wrapper).removeClass('selected');
						$(this).addClass('selected');	
						/* Fire the onchange event */
						if ($select[0].selectedIndex != $(this).attr('index') && $select[0].onchange) { $select[0].selectedIndex = $(this).attr('index'); $select[0].onchange(); }
						$select[0].selectedIndex = $(this).attr('index');
						$('span:eq(0)', $wrapper).html($(this).html());
						$ul.hide();
						return false;
				});
				/* Set the defalut */
				$('a:eq('+ this.selectedIndex +')', $ul).click();
			});/* End select each */			
			/* Apply the click handler to the Open */
			$('a.ssFormSelectOpen', this).click(function(){
														var $ul = $(this).parent().siblings('ul');
														if ($ul.css('display')=='none'){hideSelect();} /* Check if box is already open to still allow toggle, but close all other selects */
    													$ul.slideToggle();
														var offSet = ($('a.selected', $ul).offset().top - $ul.offset().top);
														$ul.animate({scrollTop: offSet});
														return false;
												});	
		}); /* End Form each */		
		/* Hide all open selects */
		var hideSelect = function(){
			$('.ssFormSelectWrapper ul:visible').hide();
		};	
		/* Check for an external click */
		var checkExternalClick = function(event) {
			if ($(event.target).parents('.ssFormSelectWrapper').length === 0) { hideSelect(); }
		};
		/* Apply document listener */
		$(document).mousedown(checkExternalClick);			
		/* Add a new handler for the reset action */
		var jReset = function(f){
			var sel;
			$('.ssFormSelectWrapper select', f).each(function(){sel = (this.selectedIndex<0) ? 0 : this.selectedIndex; $('ul', $(this).parent()).each(function(){$('a:eq('+ sel +')', this).click();});});
			$('a.ssFormCheckbox, a.ssFormRadio', f).removeClass('ssFormChecked');
			$('input:checkbox, input:radio', f).each(function(){if(this.checked){$('a', $(this).parent()).addClass('ssFormChecked');}});
		};
		this.bind('reset',function(){var action = function(){jReset(this);}; window.setTimeout(action, 10);});		
	};/* End the Plugin */
	/* Automatically apply to any forms with class ssForm (Changed by Ronni to only work on Search field) */
	$(function(){$('form.search').ssForm();	});
	//$(function(){$('form.ssForm').ssForm();	});
})(jQuery);









/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/
(function ($) {
$.fn.hint = function (blurClass) {
    if (!blurClass) blurClass = 'blur';
    return this.each(function () {
        var $input = $(this),
            alt = $input.attr('alt'),
            $form = $(this.form),
            $win = $(window);
        function remove() {
            if (this.value === alt && $input.hasClass(blurClass)) {
                $input.val('').removeClass(blurClass);
            }
        }
        // only apply logic if the element has the attribute
        if (alt) { 
            // on blur, set value to alt attr if text is blank
            $input.blur(function () {
                if (this.value === '') {
                    $input.val(alt).addClass(blurClass);
                }
            }).focus(remove).blur(); // now change all inputs to alt
            
            // clear the pre-defined text when form is submitted
            $form.submit(remove);
            $win.unload(remove); // handles Firefox's autocomplete
        }
    });
};

})(jQuery);

$(function(){ 
	// find all the input elements with alt attributes
	$('input[alt!=""]').hint();
});



// "Simple Image Gallery" (in content items) Plugin for Joomla 1.5 - Version 1.2.1
	//Deaktiveret af Ronni, da første linie ødelægger alt andet scripting på siden.
/*
function $(obj){return document.getElementById(obj);}
//bildwechsel ohne reload
function switchimg(t_gal,t_img,t_title) {
	$(t_gal).src=t_img;
	$(t_gal).alt=t_title;
	$(t_gal).title=t_title;
}
*/




