function tabify($what) //, set_selected_method)
{
	$what.tabified_current_tab = 0;
	$what.tabified_size = $what.children('.tab').size();
	
    //create the structure for the tabs
    $what.children('.tab:first').before('<div class="tabs"></div>').before('<div class="tab_contents"></div>');
    $what.children('.tabs').each(function(){
        $(this).append('<div class="header"></div><div class="content"></div><div class="footer"></div>');
    });
	
    $what.children('.tab').children('.title').each(function(){
        $(this).addClass($(this).parent().attr('id')).appendTo($what.children('.tabs').children('.content').get(0));
    });
    
    $what.children('.tabs').children('.content').children('*').wrap('<div class="tab"><div class="content"></div></div>');
    $what.children('.tabs').children('.content').children('*').prepend('<div class="header"></div>').append('<div class="footer"></div>').hover(
        function(){
            $(this).addClass('over');
        }, function(){
            $(this).removeClass('over');
        }).click(function(e){
            if(!$(this).hasClass('selected')){
                //get the name of what we clicked
                var item_name = $(this).find('.title').attr('class').split(' ')[1];
                //hide all elements which are not what we clicked
                if($.support.opacity){
                    $what.find('.tab_contents > :not(.'+item_name+')').not($('#'+item_name).next('.link')).fadeOut();
                } else {
                    $what.find('.tab_contents > :not(.'+item_name+')').not($('#'+item_name).next('.link')).css('display', 'none');
                }
                
                //show the clicked one
                if($.support.opacity){
                    $what.children('.tab_contents').children('#'+item_name).next('.link').andSelf().fadeIn();
                } else {
                    $what.children('.tab_contents').children('#'+item_name).next('.link').andSelf().css('display', 'block');
                }
                
                $what.find('.tabs .selected').removeClass('selected');
                $(this).addClass('selected');
                
                //store the value
                //$.get("http://lapalmarentacar.de/"+set_selected_method+"/"+item_name);

                $what.tabified_current_tab = $(this).index('.tab');
                $what.trigger($.Event('changeTab'));
            }
            
        });

	//prepend the previous arrow
	$('<div class="tabified_prev prev"><a href="javascript:">&lt;</a></div>').prependTo($what.find(' > .tabs > .content')).click(function(){
		if($what.tabified_current_tab > 0){
			$what.tabified_current_tab--;
			$what.children('.tabs .tab:eq('+($what.tabified_current_tab)+')').click();
		}
	});
	//append the subtitle of $what
	if($what.find(' > .subtitle').size() > 0) {
		$what.find(' > .subtitle').prependTo($what.find(' > .tabs > .content'));
	} else if($what.find(' > .header .subtitle').size() > 0){
		$what.find('> .header .subtitle').prependTo($what.find(' > .tabs > .content'));
	} else if($what.find(' > .content > .subtitle').size() > 0){
		$what.find('> .content > .subtitle').prependTo($what.find(' > .tabs > .content'));
	}
	
	//append the next arrow
	$('<div class="tabified_next next"><a href="javascript:">&gt;</a></div>').appendTo($what.find(' > .tabs > .content')).click(function(){
		if($what.tabified_current_tab < $what.tabified_size){
			$what.tabified_current_tab++;
			$what.children('.tabs .tab:eq('+($what.tabified_current_tab)+')').click();
		}
	});

    $what.children('.tab').each(function(){
        $next_sibling = $(this).next();
        $(this).appendTo($what.children('.tab_contents'));
        if($next_sibling.hasClass('link')){
            $next_sibling.appendTo($what.children('.tab_contents'));
        }
    });

    //set the first tab to be selected
    $selected = $what.find('.tab_contents > .selected');
    if($selected.size() == 0){
        $what.children('.tabs > .content > *:eq(2)').addClass('selected');
        if($.support.opacity){
            $what.children('.tab_contents > :not(:first, .link:first)').fadeOut(0);
        } else {
            $what.children('.tab_contents > :not(:first, .link:first)').css('display', 'none');
        }
    } else {
        var item_name = $selected.attr('id');
        $what.find('.tabs .'+item_name).closest('.tab').addClass('selected');
        if($.support.opacity){
            $what.find('.tab_contents > *').not($selected.next('.link').andSelf()).fadeOut(0);
        } else {
            $what.find('.tab_contents > *').not($selected.next('.link').andSelf()).css('display', 'none');
        }
        
    }
    
    
    //mark the container as tabified
    $what.addClass('tabified');
}

function set_taller(left, right)
{
    if($(left).size() > 0 && $(right).size() > 0){
        if($(left).get(0).offsetHeight > $(right).get(0).offsetHeight){
            $(left).addClass('taller');
            $(right).removeClass('taller');
        } else {
            $(right).addClass('taller');
            $(left).removeClass('taller');
        }   
    }
}

function monta_popup($trigger_elem, $popup, className)
{
    if($.support.opacity){
        $popup.css('opacity', 0);
    }
    $popup.css('display', 'none').css('visibility', 'visible').mouseover(function(e){
        e.stopPropagation();
		return false;
    });
    $trigger_elem.hover(function(e){
        e.stopPropagation();
        if(className == undefined || $trigger_elem.hasClass(className)){
            if($.support.opacity){
                $popup.stop().css('display', 'block').animate({
                    'opacity' : 1,
                    'queue' : false
                }, 400);
            } else {
                $popup.css('display', 'block');
            }
        }
        
    }, function(e){
        e.stopPropagation();
        if($.support.opacity){
            $popup.stop().animate({
                'opacity' : 0,
                'queue' : false
            }, 400, function(){
                $(this).css('display', 'none');
            });
        } else {
            $popup.css('display', 'none');
        }
    });
    
    $trigger_elem.click(function(){
        $popup.css('opacity', 0).css('display', 'none');
    });
}

function monta_fade_input_label($input, $title_elm){
    
    $title_elm.click(function(e){
        $input.focus();
    });
    
	if($input.val() == ''){
		$title_elm.stop().css('display', 'block');
		if($.support.opacity){
		    $title_elm.animate({
    			'opacity' : 1,
    			'queue' : false
    		}, 200);
		}
		
	} else {
		if($.support.opacity){
		    $title_elm.stop().animate({
    			'opacity' : 0,
    			'queue' : false
    		}, 200, function(){
    			$(this).css('display', 'none');
    		});
		} else {
		    $title_elm.css('display', 'none');
		}
	}
}

function monta_checkbox($view){
	$view.find('.block_0, label').click(function(e){
		if($view.hasClass('checked')){
			$view.removeClass('checked');
		} else {
			$view.addClass('checked');
		}
	}).hover(function(){
		$view.addClass('hover');
	}, function(){
		$view.removeClass('hover');
	});
	
	//the label already activates the checkbox, we just
	//need to fix it up here for the block
	$view.find('.block_0').click(function(e){
		$view.find('input[type=checkbox]').click();
	});
	
	$view.find('label a').click(function(e){
		e.stopPropagation();
	})
}



