/*
 * Style File - jQuery plugin for styling file input elements
 *
 * Copyright (c) 2007-2008 Mika Tuupola
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Based on work by Shaun Inman
 *   http://www.shauninman.com/archive/2007/09/10/styling_file_inputs_with_css_and_the_dom
 *
 * Revision: $Id: jquery.filestyle.js 303 2008-01-30 13:53:24Z tuupola $
 *
 */

(function($) {

    $.fn.filestyle = function(options) {

        /* TODO: This should not override CSS. */
        var settings = {
            width : 250
        };

        if(options) {
            $.extend(settings, options);
        };

        return this.each(function() {

            var self = this;
            var wrapper = $("<div>")
                            .css({
                                "width": settings.imagewidth + "px",
                                "height": settings.imageheight + "px",
                                "background": "url(" + settings.image + ") 0 0 no-repeat",
                                "background-position": "left",
                                "display": "inline",
                                "position": "absolute",
                                "overflow": "hidden"
                            });

            var filename = $('<input class="file">')
                             .addClass($(self).attr("class"))
                             .css({
                                 "display": "inline",
                                 "width": settings.width + "px"
                             });

            $(self).before(filename);
            $(self).wrap(wrapper);

            $(self).css({
                        "position": "relative",
                        "height": settings.imageheight + "px",
                        "width": settings.width + "px",
                        "display": "inline",
                        "cursor": "pointer",
                        "opacity": "0.0"
                    });


                $(self).css("margin-left", settings.imagewidth - settings.width + "px");

            $(self).bind("change", function() {
                filename.val($(self).val());
            });

        });


    };

})(jQuery);


$(document).ready(function() {

	//
	if ($.browser.mozilla && $.browser.version <= "1.9" ){
		$('body').addClass('ff2');
	}

	//
	if ($.browser.mozilla && $.browser.version <= "1.9.1" ){
		$('body').addClass('ff3');
	}

	//
	if(window.opera){
		$('html').addClass('opera');
	}

	//
	if($.browser.safari){
		$('html').addClass('safari');
	}

	//
	$('a[rel=_blank]').click(function(){
		this.target = "_blank";
	});

	//
	Cufon.replace(
		'#content p.localizer, #footer ul#navigation li a',{
			hover: true,
			fontFamily: 'HelveticaNeue Light'
		}
	);
	Cufon.replace(
		'#content h2, .home #content div.top dl dt, .home #content div.bottom dl dt, .getting-started #content div.bottom dl dt',{
			fontFamily: 'HelveticaNeue Light'
		}
	);

	// check for what is/isn't already checked and match it on the fake ones
	$("input:checkbox").each( function() {
		(this.checked) ? $("#fake"+this.id).addClass('fakechecked') : $("#fake"+this.id).removeClass('fakechecked');
		if ($(this).hasClass('error')) {
			$("#fake"+this.id).addClass('error');
		}
	});
	// function to 'check' the fake ones and their matching checkboxes
	$(".fakecheck").click(function(){
		($(this).hasClass('fakechecked')) ? $(this).removeClass('fakechecked') : $(this).addClass('fakechecked');
		$(this.hash).trigger("click");
		return false;
	});

	$("#content form.default fieldset input[type=file]").filestyle({
		image: "_ui/images/button_wybierz_zdjecie.png",
		imageheight : 43,
		imagewidth : 119,
		width : 154
	});

	$("form.loading").submit(function(){
		$('.info').show('normal');
	});

});
