/*
===============================================================================
WResize is the jQuery plugin for fixing the IE window resize bug
...............................................................................
                                               Copyright 2007 / Andrea Ercolino
-------------------------------------------------------------------------------
LICENSE: http://www.opensource.org/licenses/mit-license.php
WEBSITE: http://noteslog.com/
===============================================================================
*/

( function( $ )
{
	$.fn.wresize = function( f )
	{
		version = '1.1';
		wresize = {fired: false, width: 0};

		function resizeOnce()
		{
			if ( $.browser.msie )
			{
				if ( ! wresize.fired )
				{
					wresize.fired = true;
				}
				else
				{
					var version = parseInt( jQuery.browser.version, 10 );
					wresize.fired = false;
					if ( version < 7 )
					{
						return false;
					}
					else if ( version == 7 )
					{
						//a vertical resize is fired once, an horizontal resize twice
						var width = $( window ).width();
						if ( width != wresize.width )
						{
							wresize.width = width;
							return false;
						}
					}
				}
			}

			return true;
		}

		function handleWResize( e )
		{
			if ( resizeOnce() )
			{
				return f.apply(this, [e]);
			}
		}

		this.each( function()
		{
			if ( this == window )
			{
				$( this ).resize( handleWResize );
			}
			else
			{
				$( this ).resize( f );
			}
		} );

		return this;
	};

} ) ( jQuery );

$(function(){
	var wanda = {

		fixBackground: function(obj,sizing){


					if($(obj).length <= 0){
						return false;
					}

					if(!sizing){
						var sizing = 'scale';
					}

					var image = $(obj).css('backgroundImage');

					if (image.match(/^url\(["']?(.*\.png([?].*)?)["']?\)$/i)) {
						image = RegExp.$1;
						$(obj).css("filter", 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true", sizingMethod="' + sizing + '", src="'+ image +'")');
						$(obj).css("backgroundImage", "none");
					}



		},

		fixPng: function(obj){

					if($(obj).length <= 0){
						return false;
					}

					var sizing = 'crop';
					var image = $(obj).attr('src');
					var iwidth = $(obj).attr('width');
					var iheight = $(obj).attr('height');

					$(obj).css("filter", 'progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled="true", sizingMethod="' + sizing + '", src="'+ image +'")');
					$(obj).attr({ src: '/templates/wanda/images/spacer.gif', width : iwidth, height: iheight });

		},

		fixMainHeight: function (){
					var mainHeight = $('#main').height();
					var mainWrapHeight = $('#main-wrap').height();
					if(mainWrapHeight < mainHeight){
						$('#main-wrap').css({ height: mainHeight+'px' });
					}
		},

		setMinPageWidth: function(){
					if($(window).width() < '985'){
						$('#page').css({ width: '985px' });
					}else{
						$('#page').css({ width: 'auto' });
					}

		}
	}



	if($.browser.msie && $.browser.version <=6){
			wanda.fixBackground('.forum_title', 'crop');
			wanda.fixBackground('.HeaderYellowLeft', 'crop');
			wanda.fixBackground('.HeaderYellowRight', 'crop');
			wanda.fixBackground('.HeaderYellowCenter', 'scale');
			wanda.fixBackground('#fontShadow', 'scale');
			wanda.fixBackground('#colorShadow', 'scale');
			wanda.fixBackground('#smiliesShadow', 'scale');

			$('.pngfix').each(
				function(){
					wanda.fixPng(this);
				}
			);

			$('.button').each(
				function(){

					$(this).hover(
						function(){
							$(this).addClass("buttonHover");
						},
						function(){
							$(this).removeClass("buttonHover");
						}
					)
				}
			);
			$('.textbox').each(
				function(){

					$(this).hover(
						function(){
							$(this).addClass("textboxHover");
						},
						function(){
							$(this).removeClass("textboxHover");
						}
					)
				}
			);

	}


	if($.browser.opera){
		$('.HeaderYellowRight').css({position:'absolute', top:'0px' ,right: '-14px' });
	}
	/**
	 * search.ftl functions
	 */


	if($('#searchButton')){

		$('#searchButton').hide();

		$('#searchImage').show();

		$('#searchImage').click(
			function(){
				$('#searchButton').click();
			}
		);

		$('#searchImage').hover(
			function(){
				$(this).css({ backgroundPosition: "bottom left"});

			},
			function(){
				$(this).css({ backgroundPosition: "top left"});
			}
		);

	}
	
	/**
	 *
	 */
	$("blockquote").before($("<div>").attr("class","spacer20"));
	$("blockquote").after($("<div>").attr("class","spacer10")); 
});

