

/* Created by jankoatwarpspeed.com */

(function($) {
    $.fn.formToWizard = function(options) {
        options = $.extend({  
            submitButton: "",
            stepText: "Step",
            stepForwardText: "Nästa >",
            stepBackwardText: "< Föregående"
        }, options); 
        
        var element = this;

        var steps = $(element).find("fieldset");
        var count = steps.size();
        var submmitButtonName = "#" + options.submitButton;
        $(submmitButtonName).hide();

        // 2
        $(element).before("<ul id='steps'></ul>");

        steps.each(function(i) {
            $(this).wrap("<div id='step" + i + "'></div>");
            $(this).append("<p id='step" + i + "commands'></p>");

            // 2
            var name = $(this).find("legend").html();
            $("#steps").append("<li class='steps' id='stepDesc" + i + "'>"+options.stepText+" " + (i + 1) + "<span>" + name + "</span></li>");
            $("#stepDesc" + i).click(function(){

               steps.each(function(i) {
                   $("#step" + (i)).hide();
               });
               
               $("#step" + (i)).fadeIn(1000);
               if (i + 1 == count)
                    $(submmitButtonName).show();
                else
                    $(submmitButtonName).hide();
               selectStep(i);
            });
            if (i == 0) {
                createNextButton(i);
                selectStep(i);
            }
            else if (i == count - 1) {
                $("#step" + i).hide();
                createPrevButton(i);
            }
            else {
                $("#step" + i).hide();
                createPrevButton(i);
                createNextButton(i);
            }
        });

        function createPrevButton(i) {
            var stepName = "step" + i;
            $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Prev' class='prev'>"+options.stepBackwardText+"</a>");

            $("#" + stepName + "Prev").bind("click", function(e) {
                $("#" + stepName).hide();
                $("#step" + (i - 1)).fadeIn(1000);
                $(submmitButtonName).hide();
                selectStep(i - 1);
            });
        }

        function createNextButton(i) {
            var stepName = "step" + i;
            $("#" + stepName + "commands").append("<a href='#' id='" + stepName + "Next' class='next'>"+options.stepForwardText+"</a>");
 
            $("#" + stepName + "Next").bind("click", function(e) {
                $("#" + stepName).hide();
                $("#step" + (i + 1)).fadeIn(1000);
                if (i + 2 == count) 
                    $(submmitButtonName).show();
                selectStep(i + 1);
            });
        }

        function selectStep(i) {
            $("#steps li").removeClass("current");
            $("#stepDesc" + i).addClass("current");
        }

    }
})(jQuery); 

(function($) {
    $.fn.tipsy = function(opts) {

        opts = $.extend({fade: false, gravity: 'n'}, opts || {});
        var tip = null, cancelHide = false;

        this.hover(function() {
            
            $.data(this, 'cancel.tipsy', true);

            var tip = $.data(this, 'active.tipsy');
            if (!tip) {
                tip = $('<div class="tipsy"><div class="tipsy-inner">' + $(this).attr('title') + '</div></div>');
                tip.css({position: 'absolute', zIndex: 100000});
                $(this).attr('title', '');
                $.data(this, 'active.tipsy', tip);
            }
            
            var pos = $.extend({}, $(this).offset(), {width: this.offsetWidth, height: this.offsetHeight});
            tip.remove().css({top: 0, left: 0, visibility: 'hidden', display: 'block'}).appendTo(document.body);
            var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
            
            switch (opts.gravity.charAt(0)) {
                case 'n':
                    tip.css({top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-north');
                    break;
                case 's':
                    tip.css({top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}).addClass('tipsy-south');
                    break;
                case 'e':
                    tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}).addClass('tipsy-east');
                    break;
                case 'w':
                    tip.css({top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}).addClass('tipsy-west');
                    break;
            }

            if (opts.fade) {
                tip.css({opacity: 0, display: 'block', visibility: 'visible'}).animate({opacity: 1});
            } else {
                tip.css({visibility: 'visible'});
            }

        }, function() {
            $.data(this, 'cancel.tipsy', false);
            var self = this;
            setTimeout(function() {
                if ($.data(this, 'cancel.tipsy')) return;
                var tip = $.data(self, 'active.tipsy');
                if (opts.fade) {
                    tip.stop().fadeOut(function() { $(this).remove(); });
                } else {
                    tip.remove();
                }
            }, 100);
            
        });

    };
})(jQuery);


(function($){$.fn.hoverAccordion=function(options){options=jQuery.extend({speed:'fast',activateitem:'true',active:'active',header:'header',hover:'hover',opened:'opened',closed:'closed',keepheight:'true'},options);var thislist=this;var thisurl=window.location.href;var i=0;function doHover(obj){if($(obj).html()==undefined)obj=this;if(!thislist.is(':animated')){var newelem=$(obj).parent().children('ul');var oldelem=$(obj).parent().parent().children('li').children('ul:visible');if(options.keepheight=='true'){thisheight=maxheight;}else{thisheight=newelem.height();}if(!newelem.is(':visible')){newelem.children().hide();newelem.animate({height:thisheight},{step:function(n,fx){newelem.height(thisheight-n);},duration:options.speed}).children().show();oldelem.animate({height:'hide'},{step:function(n,fx){newelem.height(thisheight-n);},duration:options.speed}).children().hide();oldelem.parent().children('a').addClass(options.closed).removeClass(options.opened);newelem.parent().children('a').addClass(options.opened).removeClass(options.closed);}}};var itemNo=0;var maxheight=0;$(this).children('li').each(function(){var thisitem=$(this);itemNo++;var thislink=thisitem.children('a');if(thislink.length>0){thislink.hover(function(){$(this).addClass(options.hover);},function(){$(this).removeClass(options.hover);});var thishref=thislink.attr('href');if(thishref=='#'){thislink.click(function(){doHover(this);this.blur();return false;});}else if(options.activateitem=='true'&&thisurl.indexOf(thishref)>0&&thisurl.length-thisurl.lastIndexOf(thishref)==thishref.length){thislink.parent().addClass(options.active);}}var thischild=thisitem.children('ul');if(thischild.length>0){if(maxheight<thischild.height())maxheight=thischild.height();thischild.children('li.'+options.active).parent().parent().children('a').addClass(options.header);thislink.hover(function(){var t=this;i=setInterval(function(){clearInterval(i);},400);},function(){clearInterval(i);});if(options.activateitem=='true'){thischild.children('li').each(function(){var m=$(this).children('a').attr('href');if(m){if(thisurl.indexOf(m)>0&&thisurl.length-thisurl.lastIndexOf(m)==m.length){$(this).addClass(options.active).parent().parent().children('a').addClass(options.opened);}}});}else if(parseInt(options.activateitem)==itemNo){thisitem.addClass(options.active).children('a').addClass(options.opened);}}thischild.not($(this).parent().children('li.'+options.active).children('ul')).not(thischild.children('li.'+options.active).parent()).hide().parent().children('a').addClass(options.closed);});return this;};})(jQuery);


jQuery.fn.vchecks = function() {
	
	object = jQuery(this);
	object.addClass('geogoer_vchecks');
	object.find("li:first").addClass('first');
	object.find("li:last").addClass('last');
	//removing checkboxes
	object.find("input[type=checkbox]").each(function(){
		$(this).hide();
	});
	//adding images true false
	object.find("li").each(function(){
		if($(this).find("input[type=checkbox]").attr('checked') == true){
			$(this).addClass('checked');
			$(this).append('<div class="check_div"></div>');
		}
		else{
			$(this).addClass('unchecked');
			$(this).append('<div class="check_div"></div>');
		}
	});
	//binding onClick function
	object.find("li").find('span').click(function(e){
		e.preventDefault();
		check_li = $(this).parent('li');
		checkbox = $(this).parent('li').find("input[type=checkbox]");
		if(checkbox.attr('checked') == true){
			checkbox.attr('checked',false);
			check_li.removeClass('checked');
			check_li.addClass('unchecked');
		}
		else{
			checkbox.attr('checked',true);
			check_li.removeClass('unchecked');
			check_li.addClass('checked');
		}
	});
	
	//mouse over / out
	//simple
	object.find("li:not(:last,:first)").find('span').bind('mouseover', function(e){
		$(this).parent('li').addClass('hover');
	});
	object.find("li:not(:last,:first)").find('span').bind('mouseout', function(e){
		$(this).parent('li').removeClass('hover');
	});
	//first
	object.find("li:first").find('span').bind('mouseover', function(e){
		$(this).parent('li').addClass('first_hover');
	});
	object.find("li:first").find('span').bind('mouseout', function(e){
		$(this).parent('li').removeClass('first_hover');
	});
	//last
	object.find("li:last").find('span').bind('mouseover', function(e){
		$(this).parent('li').addClass('last_hover');
	});
	object.find("li:last").find('span').bind('mouseout', function(e){
		$(this).parent('li').removeClass('last_hover');
	});
}
