(function($) {
$(document).ready(function() {

	$('.postbody .content img').autoResize();

    $("#Login").hide();
    $("#LoginButton, #Login").ready(function() {
        $("#LoginButton").show();
        $("#LoginButton, #Login").click(function() {
            $("#Login").show();
        });
    });
	/*Blur Head Login User*/
	$("#LoginUser").click(function() {
		$(this).addClass('LoginUserJS');
		var LoginUser = $("#LoginUser").val();
		if(LoginUser != '') {
			$(this).val('');
		}
	}).blur(function() {
		var LoginUser = $("#LoginUser").val();
		if(LoginUser == '') {
			$(this).removeClass('LoginUserJS');
		} else {
			$(this).addClass('LoginUserJS');
		}
	}).change(function() {
		var LoginUser = $("#LoginUser").val();
		if(LoginUser == '') {
			$(this).removeClass('LoginUserJS');
		} else {
			$(this).addClass('LoginUserJS');
		}
	});
	
	/*Blur Head Login Passwd*/
	$("#LoginPasswd").click(function() {
		$(this).addClass('LoginPasswdJS');
		var LoginPasswd = $("#LoginPasswd").val();
		if(LoginPasswd != '') {
			$(this).val('');
		}
	}).blur(function() {
		var LoginPasswd = $("#LoginPasswd").val();
		if(LoginPasswd == '') {
			$(this).removeClass('LoginPasswdJS');
		} else {
			$(this).addClass('LoginPasswdJS');
		}
	}).change(function() {
		var LoginPasswd = $("#LoginPasswd").val();
		if(LoginPasswd == '') {
			$(this).removeClass('LoginPasswdJS');
		} else {
			$(this).addClass('LoginPasswdJS');
		}
	});
	/*Blur Login User*/
	$("#MainLogin input#username").click(function() {
		$(this).addClass('usernameJS');
		var usernameJS = $("#MainLogin input#username").val();
		if(usernameJS != '') {
			$(this).val('');
		}
	}).blur(function() {
		var usernameJS = $("#MainLogin input#username").val();
		if(usernameJS == '') {
			$(this).removeClass('usernameJS');
		} else {
			$(this).addClass('usernameJS');
		}
	}).change(function() {
		var usernameJS = $("#MainLogin input#username").val();
		if(usernameJS == '') {
			$(this).removeClass('usernameJS');
		} else {
			$(this).addClass('usernameJS');
		}
	});
	
	/*Blur Login Passwd*/
	$("#MainLogin input#password").click(function() {
		$(this).addClass('passwordJS');
		var passwordJS = $("#MainLogin input#password").val();
		if(passwordJS != '') {
			$(this).val('');
		}
	}).blur(function() {
		var passwordJS = $("#MainLogin input#password").val();
		if(passwordJS == '') {
			$(this).removeClass('passwordJS');
		} else {
			$(this).addClass('passwordJS');
		}
	}).change(function() {
		var passwordJS = $("#MainLogin input#password").val();
		if(passwordJS == '') {
			$(this).removeClass('passwordJS');
		} else {
			$(this).addClass('passwordJS');
		}
	});
	
	/*Profile-SubMenu*/
        var navigation = $("#navigation").html();
        $("#navigation").remove();
        $("#tabs li.activetab a").after(navigation);
        /*Farbpalette*/
        $("#bbpalette").click(function () {
            $("#colour_palette").show();
        });
        $("#colour_palette dl dt").click(function () {
            $("#colour_palette").hide();
        });        
      /* Topic Search */
      $('div.postheader .search-icon').click(function(event) {
      		event.preventDefault();
      		var searchcontainer = $('div.postheader .topic-search');
      		if(searchcontainer.hasClass('disabled'))
				searchcontainer.removeClass('disabled').addClass('active').fadeIn();
			else
				searchcontainer.removeClass('active').addClass('disabled').fadeOut();
      });
      
      /* Topic Moderation */
      $('div.postheader .mcp-icon').click(function(event) {
      		event.preventDefault();
      		var mcpcontainer = $('div.postheader .topic-moderation');
      		if(mcpcontainer.hasClass('disabled'))
      			mcpcontainer.removeClass('disabled').addClass('active').fadeIn();
			else
				mcpcontainer.removeClass('active').addClass('disabled').fadeOut();
      })
      
	$('.hide_ucpinfo').bind('click', function(event) {
		event.preventDefault();
		$('.shopware_newuser').slideUp();
		
		$.post('ucp.php?mode=hideReminder', function(data) {
		});
	});
	
	$.ajax({
		dataType: 'jsonp',
		type: 'GET',
		url: 'http://wiki.shopware.de/shopware.php?sViewport=forum',
		success: function(response) {
			$('.wiki-topics .box-first .loading').fadeOut('slow');
			$.each(response, function(idx, el) {
				var link = $('<a>', {
					'href': 'http://wiki.shopware.de/' + el.linkDetails,
					'html': el.articleName
				}).appendTo($('.wiki-topics .box-first'));
			});
		}
	})
});
})(jQuery);

(function ($) {

    /**
     * Replaces placeholders in a passed string
     * Example: $.format('<div class="{0}"'>{1}</div>, [value for %0], [value for %1], ...)
     * 
     * @param [string] string which needs to be formatted
     * @return [string] the formatted string
     */
    $.format = function (str) {
        for (var i = 1; i < arguments.length; i++) {
            str = str.replace('{' + (i - 1) + '}', arguments[i]);
        }
        return str;
    };

    /**
     * jQuery Auto-Resize
     *
     * Provides a nice and simple way to resize images based
     * on the parent container element (configurable)
     *
     * @author: st.pohl <stp@shopware.de>
     * @date: 2012-01-03
     *
     * @param [object] settings - user settings
     * @return [object] incoming selector
     */
    $.fn.autoResize = function (settings) {

        // Default plugin settings
        var config = {
            container:'.content',
            cls:'img-container',
            maxImgWidth:null,
            infoBarTpl:'<div class="img-infobar" style="width:{0}px"><p>Das Bild wurde automatisch auf {1}% der Originalgr&ouml;&szlig;e runterskaliert. Zum Vergr&ouml;&szlig;ern bitte hier klicken.</p></div>'
        };

        // Extend default configuration with the passed user settings
        $.extend(config, settings || {});

        config.maxImgWidth = $(config.container).innerWidth();
        
        return this.each(function () {
            var $this = $(this), clone = $this.clone(), imgWidth = $this.width(), percent, infoBar;

            if (imgWidth > config.maxImgWidth) {
            	// Wrap image into a div container
            	var container = $('<div>', { 'class': config.cls, 'html': clone });
            	$this.replaceWith(container);
            
                clone.attr('width', config.maxImgWidth);
                percent = config.maxImgWidth * 100 / imgWidth;
                
                percent = (Math.round(percent * 100) / 100) + '';
                percent = percent.replace('.', ',');

                infoBar = $.format(config.infoBarTpl, config.maxImgWidth, percent);
                infoBar = $(infoBar).appendTo(container);
                
                $(infoBar).bind('click', function(event) {
                	event.preventDefault();
                	
                	if(~~clone.attr('width') === config.maxImgWidth) {
                		clone.attr('width', imgWidth);
                		container.width(imgWidth);
                	} else {
                		clone.attr('width', config.maxImgWidth);
                		container.width(config.maxImgWidth);
                	}
                });
                console.log(clone);
            }
        });
    };
})(jQuery);
