/*
    PROMOCJE
    www.zdzislowicz.pl
*/
jQuery(document).ready(function()
{
    promocjaPokaz = 0;
    promocjaUkryj = 0;
    timeoutID = setTimeout(refresh, 6000);
    blokada = false;
    blokadaLinkow = false;

    // pokaz pierwsza
    jQuery('#polecamy_box li').eq(0).show();

    jQuery('#polecamy_box').mouseover(function(){
        clearTimeout(timeoutID);
    });

    jQuery('#polecamy_box').mouseout(function(){
        timeoutID = setTimeout(refresh, 6000);
    });

    jQuery('.polecamyPrev').click(
        function()
        {
            if(!blokadaLinkow)
            {
                promocjaUkryj = promocjaPokaz;
                promocjaPokaz--;
                if(promocjaPokaz < 0)
                    promocjaPokaz = jQuery('#polecamy_box li').length-1;
                jQuery('#polecamy_box li').eq(promocjaUkryj).fadeOut("fast",
                    function()
                    {
                        jQuery('#polecamy_box li').eq(promocjaPokaz).fadeIn("fast");
                    }
                );
                blokada = true;
                blokadaLinkow = true;
                setTimeout(odblokujLinki, 600);
            }
        }
    );

    jQuery('.polecamyNext').click(
        function()
        {
            if(!blokadaLinkow)
            {
                promocjaUkryj = promocjaPokaz;
                promocjaPokaz++;
                if(promocjaPokaz == jQuery('#polecamy_box li').length)
                    promocjaPokaz = 0;
                jQuery('#polecamy_box li').eq(promocjaUkryj).fadeOut("fast",
                    function()
                    {
                        jQuery('#polecamy_box li').eq(promocjaPokaz).fadeIn("fast");
                    }
                );
                blokada = true;
                blokadaLinkow = true;
                setTimeout(odblokujLinki, 600);
            }
        }
    );
});

function odblokujLinki() {
  blokadaLinkow = false;
}

function refresh() {
     timeoutID = setTimeout(refresh, 6000);

    if(blokada)
        blokada = false;
    else
    {
        promocjaUkryj = promocjaPokaz;
        promocjaPokaz++;
        if(promocjaPokaz == jQuery('#polecamy_box li').length)
            promocjaPokaz = 0;

        jQuery('#polecamy_box li').eq(promocjaUkryj).fadeOut("fast",
            function()
            {
                jQuery('#polecamy_box li').eq(promocjaPokaz).fadeIn("fast");
            }
        );
    }
}

/*
    OBRAZKI
    www.zdzislowicz.pl
*/
jQuery(document).ready(function()
{
    jQuery(".fadeEffect").fadeTo("fast", 0.6);
    jQuery(".fadeEffect").hover(function(){
    jQuery(this).fadeTo("fast", 1.0);
    },function(){
    jQuery(this).fadeTo("fast", 0.6);
    });
});

/*
    ZMIANA CONTENTU
    www.zdzislowicz.pl
*/
jQuery(document).ready(function(){
    var ukryj = "0";
    var ukryjProdukt = "0_0";

    jQuery('#rozwin_' + ukryj).show();
    jQuery('#rozwin_' + ukryjProdukt).show();
    jQuery('#' + ukryjProdukt).css('font-weight', 'bold');
    jQuery('#' + ukryj).css('background-position', 'bottom');

    jQuery('.fadein').click(function(){

        var id = jQuery(this).attr('id');
        if(ukryj != id)
        {
            jQuery('#' + id).css('background-position', 'bottom');
            jQuery('#' + ukryj).css('background-position', 'top');
            if(ukryj=="")
            {
                jQuery('#rozwin_' + id).fadeIn("fast");
            }
            else
            {
                jQuery('#rozwin_'+ukryj).fadeOut("fast",
                    function()
                    {
                        jQuery('#rozwin_' + id).fadeIn("fast");
                        jQuery('#rozwin_'+ukryjProdukt).hide();
                        if(ukryjProdukt != "")
                        {
                            jQuery('#' + ukryjProdukt).css('font-weight', 'normal');
                        }

                        ukryjProdukt = "";

                        if(document.getElementById(id + '_0') != undefined)
                        {
                            jQuery('#rozwin_' + id + '_0').fadeIn('fast');
                            jQuery('#' + id + '_0').css('font-weight', 'bold');
                            ukryjProdukt = id + '_0';
                        }
                    }
                );
            }
        }
        ukryj = id;
        return false;
    });

    jQuery('.fadein_produkt').click(function(){
        var id = jQuery(this).attr('id');
        if(ukryjProdukt != id)
        {
            if(ukryjProdukt=="")
            {
                jQuery('#rozwin_' + id).fadeIn("fast");
                jQuery('#' + id).css('font-weight', 'bold');
            }
            else
            {
                jQuery('#' + ukryjProdukt).css('font-weight', 'normal');
                jQuery('#' + id).css('font-weight', 'bold');
                jQuery('#rozwin_'+ukryjProdukt).fadeOut("fast",
                    function()
                    {
                        jQuery('#rozwin_' + id).fadeIn("fast");
                    }
                );
            }
        }
        ukryjProdukt = id;
        return false;
    });

});

/*
    WALIDACJA
    www.zdzislowicz.pl
*/
/*
 * opcje:
 * tag: checkbox, radio, select, default->reszta
 */
(function(jQuery) {
	jQuery.fn.validate = function(options) {

		var options = jQuery.extend({
			validation: 'single',
			file: '/ajax/walidacja/walidacja.php',
			tag: 'text',
			phpValidation: true
		}, options);

		var jQuerythis = jQuery(this);

		var errors = 0;

		function init()
        {
			if (options.validation == 'single')
            {
                if(
                    jQuerythis.attr('name') == "imie" ||
                    jQuerythis.attr('name') == "nazwisko" ||
                    jQuerythis.attr('name') == "tresc" ||
                    jQuerythis.attr('name') == "telefon"
                )
                {
 					jQuerythis.blur(function(e) {
						validateSingle(jQuery(this));
					});
					jQuerythis.keyup(function(e) {
						validateSingle(jQuery(this));
					});
                }
				if (options.tag == 'checkbox' || options.tag == 'radio' || options.tag == 'select')
					jQuerythis.change(function() {
						validateSingle(jQuery(this));
					});
				else
                {
                /*
					jQuerythis.keyup(function(e) {
						validateSingle(jQuery(this));
					});
                */
					jQuerythis.change(function() {
						validateSingle(jQuery(this));
					});
                }
            }
			else
				validateAll();
		}

		function validateSingle(jQueryitem) {
			var value = '';
			switch(options.tag) {
				case 'checkbox':
					jQueryitem.each(function(index, item) {
						if (jQuery(item).attr('checked'))
							value += jQuery(item).attr('value')+';';
					});
					value = value.substr(0, value.length - 1);
				break;
				case 'radio':
					jQueryitem.each(function(index, item) {
						if (jQuery(item).attr('checked'))
							value = jQuery(item).attr('value');
					});
				break;
				default:
					value = jQueryitem.val();
				break;
			}
			if (!options.phpValidation) {
				//tutaj twoja walidacja w JS
				var isOk = true;
				var komunikatOk = '';
				var komunikatFail = 'jest zle'

				switch(jQuerythis.attr('name')) {
					case 'tresc':
						if (value.length < 10) {
							isOk = false;
        					komunikatFail = 'Twoja wiadomość jest zbyt krótka.';
						}
                        else
                            komunikatOk = '';
					break;
					case 'email':
						komunikatOk = 'dobry email';
						komunikatFail = 'zly email';
						if (value == '') {
							isOk = false;
						}
					break;
					case 'telefon':
                        var ValidChars = "0123456789-+";
                        var IsNumber=true;
                        var Char;


                        for (i = 0; i < value.length && IsNumber == true; i++)
                        {
                            Char = value.charAt(i);
                            if (ValidChars.indexOf(Char) == -1)
                            {
                                IsNumber = false;
                            }
                        }
                        if(!IsNumber)
                        {
                            komunikatFail = 'Podany numer jest nieprawidłowy.';
                            isOk = false;
                        }
                        else if(value.length == 0)
                        {
                            komunikatFail = 'To pole nie zostało uzupełnione.';
                            isOk = false;
                        }
                        else if(value.length < 7)
                        {
                            komunikatFail = 'Podany numer jest zbyt krótki.';
                            isOk = false;
                        }
                        else
                            komunikatOk = '';
					break;
					case 'imie':
						if (value.length < 1) {
							isOk = false;
        					komunikatFail = 'To pole nie zostało uzupełnione.';
						}
						else if (value.length > 40) {
							isOk = false;
        					komunikatFail = 'To pole powinno zawierać maksymalnie 40 znaków.';
						}
                        else
                            komunikatOk = '';
					break;
					case 'nazwisko':
						if (value.length < 1) {
							isOk = false;
        					komunikatFail = 'To pole nie zostało uzupełnione.';
						}
						else if (value.length > 40) {
							isOk = false;
        					komunikatFail = 'To pole powinno zawierać maksymalnie 40 znaków.';
						}
                        else
                            komunikatOk = '';
					break;
				}
				if (isOk) {
					jQuery('.' + jQueryitem.attr('name') + '_ok').html(komunikatOk).show();
					jQuery('.' + jQueryitem.attr('name') + '_not_ok').hide();
				} else {
					jQuery('.' + jQueryitem.attr('name') + '_not_ok').html(komunikatFail).show();
					jQuery('.' + jQueryitem.attr('name') + '_ok').hide();
				}
			} else {
				//a tutaj walidacja w PHP
				jQuery.ajax({
					type: 'post',
					url: options.file,
					data: 'value='+value+'&type='+jQueryitem.attr('name'),
					async: false,
					success: function(response){
						var res = response.split(';');
						if (res[0] == '1') {
							jQuery('.' + jQueryitem.attr('name') + '_ok').html(res[1]).show();
							jQuery('.' + jQueryitem.attr('name') + '_not_ok').hide();
						}
						else {
							jQuery('.' + jQueryitem.attr('name') + '_not_ok').html(res[1]).show();
							jQuery('.' + jQueryitem.attr('name') + '_ok').hide();
						}
					}
				});
			}
		}

		function validateAll() {
			jQueryfind = jQuerythis.find('input:not(input:checkbox, input:radio, input:submit, input:button)');

			if (jQueryfind.length > 0)
				jQueryfind.each(function(index, itemm) {
					validateSingle(jQuery(itemm));
				});
			jQueryfind = jQuerythis.find('textarea');
			if (jQueryfind.length > 0)
				jQueryfind.each(function(index, itemm) {
					validateSingle(jQuery(itemm));
				});

			options.tag = 'select';
			jQueryfind = jQuerythis.find('select');
			if (jQueryfind.length > 0)
				jQueryfind.each(function(index, itemm) {
					validateSingle(jQuery(itemm));
				});

			jQueryfind = jQuerythis.find('input:checkbox');
			if (jQueryfind.length > 0) {
				options.tag = 'checkbox';
				validateSingle(jQueryfind);
			}

			jQueryfind = jQuerythis.find('input:radio');
			if (jQueryfind.length > 0) {
				options.tag = 'radio';
				validateSingle(jQueryfind);
			}

			jQuery('.not_ok').each(function(index, item) {
				if (jQuery(item).css('display') != 'none')
					errors++;
			});
		}

		init();
		if (errors > 0)
			return errors;
		else
			return this;
	};
})(jQuery);


/*
    CZCIONKA
    www.zdzislowicz.pl
*/
jQuery(document).ready(function()
{
    var czcionkaWczesniej = "";
	jQuery('.czcionka a').click(rozmiarCzcionki);
	if ( getCookie('czcionka') )
	{
		rozmiarCzcionki(getCookie('czcionka'));
	}
    else
        jQuery('.small').css('text-decoration', 'underline');
});

function rozmiarCzcionki(typ) {
	if (typeof typ == 'string')
		var tekst = typ;
	else
		var tekst = jQuery(this).attr('class');
	var rozmiar = '100%';
	switch(tekst)
	{
		case 'small': rozmiar = '100%'; break;
		case 'big': rozmiar = '110%'; break;
        case 'bigger': rozmiar = '120%';
        break;
	}
	jQuery('.blok p').css('font-size', rozmiar);
	jQuery('.blok li').css('font-size', rozmiar);
	jQuery('.blok td').css('font-size', rozmiar);
	// jQuery('.blok a').css('font-size', rozmiar);

	setCookie('czcionka', tekst, '', '/', '', '');

    jQuery('.small').css('text-decoration', 'none');
    jQuery('.big').css('text-decoration', 'none');
    jQuery('.bigger').css('text-decoration', 'none');
    jQuery('.' + tekst).css('text-decoration', 'underline');
	return false;
}

/*
    GET/SET COOKIE
    www.zdzislowicz.pl
*/
function getCookie(name)
{
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false;

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		a_temp_cookie = a_all_cookies[i].split( '=' );
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+jQuery/g, '');
		if ( cookie_name == name )
		{
			b_cookie_found = true;
			if ( a_temp_cookie.length > 1 )
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+jQuery/g, '') );
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
		return null;
}

function setCookie( name, value, expires, path, domain, secure )
{
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires )
        expires = expires * 1000 * 60 * 60 * 24;
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}



//** jQuery Scroll to Top Control script- (c) Dynamic Drive DHTML code library: http://www.dynamicdrive.com.
//** Available/ usage terms at http://www.dynamicdrive.com (March 30th, 09')
//** v1.1 (April 7th, 09'):
//** 1) Adds ability to scroll to an absolute position (from top of page) or specific element on the page instead.
//** 2) Fixes scroll animation not working in Opera.


var scrolltotop={
	//startline: Integer. Number of pixels from top of doc scrollbar is scrolled before showing control
	//scrollto: Keyword (Integer, or "Scroll_to_Element_ID"). How far to scroll document up when control is clicked on (0=top).
	setting: {startline:100, scrollto: 0, scrollduration:300, fadeduration:[500, 100]},
	controlHTML: '', //HTML for control, which is auto wrapped in DIV w/ ID="topcontrol"
	controlattrs: {offsetx:5, offsety:5}, //offset of control relative to right/ bottom of window corner
	anchorkeyword: '#top', //Enter href value of HTML anchors on the page that should also act as "Scroll Up" links

	state: {isvisible:false, shouldvisible:false},

	scrollup:function(){
		if (!this.cssfixedsupport) //if control is positioned using JavaScript
			this.jQuerycontrol.css({opacity:0}) //hide control immediately after clicking it
		var dest=isNaN(this.setting.scrollto)? this.setting.scrollto : parseInt(this.setting.scrollto)
		if (typeof dest=="string" && jQuery('#'+dest).length==1) //check element set by string exists
			dest=jQuery('#'+dest).offset().top
		else
			dest=0
		this.jQuerybody.animate({scrollTop: dest}, this.setting.scrollduration);
	},

	keepfixed:function(){
		var jQuerywindow=jQuery(window)
		var controlx=jQuerywindow.scrollLeft() + jQuerywindow.width() - this.jQuerycontrol.width() - this.controlattrs.offsetx
		var controly=jQuerywindow.scrollTop() + jQuerywindow.height() - this.jQuerycontrol.height() - this.controlattrs.offsety
		this.jQuerycontrol.css({left:controlx+'px', top:controly+'px'})
	},

	togglecontrol:function(){
		var scrolltop=jQuery(window).scrollTop()
		if (!this.cssfixedsupport)
			this.keepfixed()
		this.state.shouldvisible=(scrolltop>=this.setting.startline)? true : false
		if (this.state.shouldvisible && !this.state.isvisible){
			this.jQuerycontrol.stop().animate({opacity:1}, this.setting.fadeduration[0])
			this.state.isvisible=true
		}
		else if (this.state.shouldvisible==false && this.state.isvisible){
			this.jQuerycontrol.stop().animate({opacity:0}, this.setting.fadeduration[1])
			this.state.isvisible=false
		}
	},

	init:function(){
		jQuery(document).ready(function(jQuery){
			var mainobj=scrolltotop
			var iebrws=document.all
			mainobj.cssfixedsupport=!iebrws || iebrws && document.compatMode=="CSS1Compat" && window.XMLHttpRequest //not IE or IE7+ browsers in standards mode
			mainobj.jQuerybody=(window.opera)? (document.compatMode=="CSS1Compat"? jQuery('html') : jQuery('body')) : jQuery('html,body')
			mainobj.jQuerycontrol=jQuery('<div id="topcontrol">'+mainobj.controlHTML+'</div>')
				.css({position:mainobj.cssfixedsupport? 'fixed' : 'absolute', bottom:mainobj.controlattrs.offsety, right:mainobj.controlattrs.offsetx, opacity:0, cursor:'pointer'})
				.attr({title:'Scroll Back to Top'})
				.click(function(){mainobj.scrollup(); return false})
				.appendTo('body')
			if (document.all && !window.XMLHttpRequest && mainobj.jQuerycontrol.text()!='') //loose check for IE6 and below, plus whether control contains any text
				mainobj.jQuerycontrol.css({width:mainobj.jQuerycontrol.width()}) //IE6- seems to require an explicit width on a DIV containing text
			mainobj.togglecontrol()
			jQuery('a[href="' + mainobj.anchorkeyword +'"]').click(function(){
				mainobj.scrollup()
				return false
			})
			jQuery(window).bind('scroll resize', function(e){
				mainobj.togglecontrol()
			})
		})
	}
}
scrolltotop.init()

/**
 * jQuery lightBox plugin
 * This jQuery plugin was inspired and based on Lightbox 2 by Lokesh Dhakar (http://www.huddletogether.com/projects/lightbox2/)
 * and adapted to me for use like a plugin from jQuery.
 * @name jquery-lightbox-0.5.js
 * @author Leandro Vieira Pinho - http://leandrovieira.com
 * @version 0.5
 * @date April 11, 2008
 * @category jQuery plugin
 * @copyright (c) 2008 Leandro Vieira Pinho (leandrovieira.com)
 * @license CC Attribution-No Derivative Works 2.5 Brazil - http://creativecommons.org/licenses/by-nd/2.5/br/deed.en_US
 * @example Visit http://leandrovieira.com/projects/jquery/lightbox/ for more informations about this jQuery plugin
 */


jQuery(function() {
  jQuery('.light a').lightBox();
});


// Offering a Custom Alias suport - More info: http://docs.jquery.com/Plugins/Authoring#Custom_Alias
(function(jQuery) {
	/**
	 * jQuery is an alias to jQuery object
	 *
	 */
	jQuery.fn.lightBox = function(settings) {
		// Settings to configure the jQuery lightBox plugin how you like
		settings = jQuery.extend({
			// Configuration related to overlay
			overlayBgColor: 		'#000',		// (string) Background color to overlay; inform a hexadecimal value like: #RRGGBB. Where RR, GG, and BB are the hexadecimal values for the red, green, and blue values of the color.
			overlayOpacity:			0.8,		// (integer) Opacity value to overlay; inform: 0.X. Where X are number from 0 to 9
			// Configuration related to navigation
			fixedNavigation:		false,		// (boolean) Boolean that informs if the navigation (next and prev button) will be fixed or not in the interface.
			// Configuration related to images
			imageLoading:			'/img/lightbox/lightbox-ico-loading.gif',		// (string) Path and the name of the loading icon
			imageBtnPrev:			'/img/lightbox/lightbox-btn-prev.gif',			// (string) Path and the name of the prev button image
			imageBtnNext:			'/img/lightbox/lightbox-btn-next.gif',			// (string) Path and the name of the next button image
			imageBtnClose:			'/img/lightbox/lightbox-btn-close.gif',		// (string) Path and the name of the close btn
			imageBlank:				'/img/lightbox/lightbox-blank.gif',			// (string) Path and the name of a blank image (one pixel)
			// Configuration related to container image box
			containerBorderSize:	10,			// (integer) If you adjust the padding in the CSS for the container, #lightbox-container-image-box, you will need to update this value
			containerResizeSpeed:	400,		// (integer) Specify the resize duration of container image. These number are miliseconds. 400 is default.
			// Configuration related to texts in caption. For example: Image 2 of 8. You can alter either "Image" and "of" texts.
			txtImage:				'Image',	// (string) Specify text "Image"
			txtOf:					'of',		// (string) Specify text "of"
			// Configuration related to keyboard navigation
			keyToClose:				'c',		// (string) (c = close) Letter to close the jQuery lightBox interface. Beyond this letter, the letter X and the SCAPE key is used to.
			keyToPrev:				'p',		// (string) (p = previous) Letter to show the previous image
			keyToNext:				'n',		// (string) (n = next) Letter to show the next image.
			// Don?t alter these variables in any way
			imageArray:				[],
			activeImage:			0
		},settings);
		// Caching the jQuery object with all elements matched
		var jQueryMatchedObj = this; // This, in this context, refer to jQuery object
		/**
		 * Initializing the plugin calling the start function
		 *
		 * @return boolean false
		 */
		function _initialize() {
			_start(this,jQueryMatchedObj); // This, in this context, refer to object (link) which the user have clicked
			return false; // Avoid the browser following the link
		}
		/**
		 * Start the jQuery lightBox plugin
		 *
		 * @param object objClicked The object (link) whick the user have clicked
		 * @param object jQueryMatchedObj The jQuery object with all elements matched
		 */
		function _start(objClicked,jQueryMatchedObj) {
			// Hime some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			jQuery('embed, object, select').css({ 'visibility' : 'hidden' });
			// Call the function to create the markup structure; style some elements; assign events in some elements.
			_set_interface();
			// Unset total images in imageArray
			settings.imageArray.length = 0;
			// Unset image active information
			settings.activeImage = 0;
			// We have an image set? Or just an image? Let?s see it.
			if ( jQueryMatchedObj.length == 1 ) {
				settings.imageArray.push(new Array(objClicked.getAttribute('href'),objClicked.getAttribute('title')));
			} else {
				// Add an Array (as many as we have), with href and title atributes, inside the Array that storage the images references
				for ( var i = 0; i < jQueryMatchedObj.length; i++ ) {
					settings.imageArray.push(new Array(jQueryMatchedObj[i].getAttribute('href'),jQueryMatchedObj[i].getAttribute('title')));
				}
			}
			while ( settings.imageArray[settings.activeImage][0] != objClicked.getAttribute('href') ) {
				settings.activeImage++;
			}
			// Call the function that prepares image exibition
			_set_image_to_view();
		}
		/**
		 * Create the jQuery lightBox plugin interface
		 *
		 * The HTML markup will be like that:
			<div id="jquery-overlay"></div>
			<div id="jquery-lightbox">
				<div id="lightbox-container-image-box">
					<div id="lightbox-container-image">
						<img src="../fotos/XX.jpg" id="lightbox-image">
						<div id="lightbox-nav">
							<a href="#" id="lightbox-nav-btnPrev"></a>
							<a href="#" id="lightbox-nav-btnNext"></a>
						</div>
						<div id="lightbox-loading">
							<a href="#" id="lightbox-loading-link">
								<img src="../images/lightbox-ico-loading.gif">
							</a>
						</div>
					</div>
				</div>
				<div id="lightbox-container-image-data-box">
					<div id="lightbox-container-image-data">
						<div id="lightbox-image-details">
							<span id="lightbox-image-details-caption"></span>
							<span id="lightbox-image-details-currentNumber"></span>
						</div>
						<div id="lightbox-secNav">
							<a href="#" id="lightbox-secNav-btnClose">
								<img src="../images/lightbox-btn-close.gif">
							</a>
						</div>
					</div>
				</div>
			</div>
		 *
		 */
		function _set_interface() {
			// Apply the HTML markup into body tag
			jQuery('body').append('<div id="jquery-overlay"></div><div id="jquery-lightbox"><div id="lightbox-container-image-box"><div id="lightbox-container-image"><img id="lightbox-image"><div style="" id="lightbox-nav"><a href="#" id="lightbox-nav-btnPrev"></a><a href="#" id="lightbox-nav-btnNext"></a></div><div id="lightbox-loading"><a href="#" id="lightbox-loading-link"><img src="' + settings.imageLoading + '"></a></div></div></div><div id="lightbox-container-image-data-box"><div id="lightbox-container-image-data"><div id="lightbox-image-details"><span id="lightbox-image-details-caption"></span><span id="lightbox-image-details-currentNumber"></span></div><div id="lightbox-secNav"><a href="#" id="lightbox-secNav-btnClose"><img src="' + settings.imageBtnClose + '"></a></div></div></div></div>');
			// Get page sizes
			var arrPageSizes = ___getPageSize();
			// Style overlay and show it
			jQuery('#jquery-overlay').css({
				backgroundColor:	settings.overlayBgColor,
				opacity:			settings.overlayOpacity,
				width:				arrPageSizes[0],
				height:				arrPageSizes[1]
			}).fadeIn();
			// Get page scroll
			var arrPageScroll = ___getPageScroll();
			// Calculate top and left offset for the jquery-lightbox div object and show it
			jQuery('#jquery-lightbox').css({
				top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
				left:	arrPageScroll[0]
			}).show();
			// Assigning click events in elements to close overlay
			jQuery('#jquery-overlay,#jquery-lightbox').click(function() {
				_finish();
			});
			// Assign the _finish function to lightbox-loading-link and lightbox-secNav-btnClose objects
			jQuery('#lightbox-loading-link,#lightbox-secNav-btnClose').click(function() {
				_finish();
				return false;
			});
			// If window was resized, calculate the new overlay dimensions
			jQuery(window).resize(function() {
				// Get page sizes
				var arrPageSizes = ___getPageSize();
				// Style overlay and show it
				jQuery('#jquery-overlay').css({
					width:		arrPageSizes[0],
					height:		arrPageSizes[1]
				});
				// Get page scroll
				var arrPageScroll = ___getPageScroll();
				// Calculate top and left offset for the jquery-lightbox div object and show it
				jQuery('#jquery-lightbox').css({
					top:	arrPageScroll[1] + (arrPageSizes[3] / 10),
					left:	arrPageScroll[0]
				});
			});
		}
		/**
		 * Prepares image exibition; doing a image?s preloader to calculate it?s size
		 *
		 */
		function _set_image_to_view() { // show the loading
			// Show the loading
			jQuery('#lightbox-loading').show();
			if ( settings.fixedNavigation ) {
				jQuery('#lightbox-image,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
			} else {
				// Hide some elements
				jQuery('#lightbox-image,#lightbox-nav,#lightbox-nav-btnPrev,#lightbox-nav-btnNext,#lightbox-container-image-data-box,#lightbox-image-details-currentNumber').hide();
			}
			// Image preload process
			var objImagePreloader = new Image();
			objImagePreloader.onload = function() {
				jQuery('#lightbox-image').attr('src',settings.imageArray[settings.activeImage][0]);
				// Perfomance an effect in the image container resizing it
				_resize_container_image_box(objImagePreloader.width,objImagePreloader.height);
				//	clear onLoad, IE behaves irratically with animated gifs otherwise
				objImagePreloader.onload=function(){};
			};
			objImagePreloader.src = settings.imageArray[settings.activeImage][0];
		};
		/**
		 * Perfomance an effect in the image container resizing it
		 *
		 * @param integer intImageWidth The image?s width that will be showed
		 * @param integer intImageHeight The image?s height that will be showed
		 */
		function _resize_container_image_box(intImageWidth,intImageHeight) {
			// Get current width and height
			var intCurrentWidth = jQuery('#lightbox-container-image-box').width();
			var intCurrentHeight = jQuery('#lightbox-container-image-box').height();
			// Get the width and height of the selected image plus the padding
			var intWidth = (intImageWidth + (settings.containerBorderSize * 2)); // Plus the image?s width and the left and right padding value
			var intHeight = (intImageHeight + (settings.containerBorderSize * 2)); // Plus the image?s height and the left and right padding value
			// Diferences
			var intDiffW = intCurrentWidth - intWidth;
			var intDiffH = intCurrentHeight - intHeight;
			// Perfomance the effect
			jQuery('#lightbox-container-image-box').animate({ width: intWidth, height: intHeight },settings.containerResizeSpeed,function() { _show_image(); });
			if ( ( intDiffW == 0 ) && ( intDiffH == 0 ) ) {
				if ( jQuery.browser.msie ) {
					___pause(250);
				} else {
					___pause(100);
				}
			}
			jQuery('#lightbox-container-image-data-box').css({ width: intImageWidth });
			jQuery('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ height: intImageHeight + (settings.containerBorderSize * 2) });
		};
		/**
		 * Show the prepared image
		 *
		 */
		function _show_image() {
			jQuery('#lightbox-loading').hide();
			jQuery('#lightbox-image').fadeIn(function() {
				_show_image_data();
				_set_navigation();
			});
			_preload_neighbor_images();
		};
		/**
		 * Show the image information
		 *
		 */
		function _show_image_data() {
			jQuery('#lightbox-container-image-data-box').slideDown('fast');
			jQuery('#lightbox-image-details-caption').hide();
			if ( settings.imageArray[settings.activeImage][1] ) {
				jQuery('#lightbox-image-details-caption').html(settings.imageArray[settings.activeImage][1]).show();
			}
			// If we have a image set, display 'Image X of X'
			if ( settings.imageArray.length > 1 ) {
				jQuery('#lightbox-image-details-currentNumber').html(settings.txtImage + ' ' + ( settings.activeImage + 1 ) + ' ' + settings.txtOf + ' ' + settings.imageArray.length).show();
			}
		}
		/**
		 * Display the button navigations
		 *
		 */
		function _set_navigation() {
			jQuery('#lightbox-nav').show();

			// Instead to define this configuration in CSS file, we define here. And it?s need to IE. Just.
			jQuery('#lightbox-nav-btnPrev,#lightbox-nav-btnNext').css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });

			// Show the prev button, if not the first image in set
			if ( settings.activeImage != 0 ) {
				if ( settings.fixedNavigation ) {
					jQuery('#lightbox-nav-btnPrev').css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' })
						.unbind()
						.bind('click',function() {
							settings.activeImage = settings.activeImage - 1;
							_set_image_to_view();
							return false;
						});
				} else {
					// Show the images button for Next buttons
					jQuery('#lightbox-nav-btnPrev').unbind().hover(function() {
						jQuery(this).css({ 'background' : 'url(' + settings.imageBtnPrev + ') left 15% no-repeat' });
					},function() {
						jQuery(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
					}).show().bind('click',function() {
						settings.activeImage = settings.activeImage - 1;
						_set_image_to_view();
						return false;
					});
				}
			}

			// Show the next button, if not the last image in set
			if ( settings.activeImage != ( settings.imageArray.length -1 ) ) {
				if ( settings.fixedNavigation ) {
					jQuery('#lightbox-nav-btnNext').css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' })
						.unbind()
						.bind('click',function() {
							settings.activeImage = settings.activeImage + 1;
							_set_image_to_view();
							return false;
						});
				} else {
					// Show the images button for Next buttons
					jQuery('#lightbox-nav-btnNext').unbind().hover(function() {
						jQuery(this).css({ 'background' : 'url(' + settings.imageBtnNext + ') right 15% no-repeat' });
					},function() {
						jQuery(this).css({ 'background' : 'transparent url(' + settings.imageBlank + ') no-repeat' });
					}).show().bind('click',function() {
						settings.activeImage = settings.activeImage + 1;
						_set_image_to_view();
						return false;
					});
				}
			}
			// Enable keyboard navigation
			_enable_keyboard_navigation();
		}
		/**
		 * Enable a support to keyboard navigation
		 *
		 */
		function _enable_keyboard_navigation() {
			jQuery(document).keydown(function(objEvent) {
				_keyboard_action(objEvent);
			});
		}
		/**
		 * Disable the support to keyboard navigation
		 *
		 */
		function _disable_keyboard_navigation() {
			jQuery(document).unbind();
		}
		/**
		 * Perform the keyboard actions
		 *
		 */
		function _keyboard_action(objEvent) {
			// To ie
			if ( objEvent == null ) {
				keycode = event.keyCode;
				escapeKey = 27;
			// To Mozilla
			} else {
				keycode = objEvent.keyCode;
				escapeKey = objEvent.DOM_VK_ESCAPE;
			}
			// Get the key in lower case form
			key = String.fromCharCode(keycode).toLowerCase();
			// Verify the keys to close the ligthBox
			if ( ( key == settings.keyToClose ) || ( key == 'x' ) || ( keycode == escapeKey ) ) {
				_finish();
			}
			// Verify the key to show the previous image
			if ( ( key == settings.keyToPrev ) || ( keycode == 37 ) ) {
				// If we?re not showing the first image, call the previous
				if ( settings.activeImage != 0 ) {
					settings.activeImage = settings.activeImage - 1;
					_set_image_to_view();
					_disable_keyboard_navigation();
				}
			}
			// Verify the key to show the next image
			if ( ( key == settings.keyToNext ) || ( keycode == 39 ) ) {
				// If we?re not showing the last image, call the next
				if ( settings.activeImage != ( settings.imageArray.length - 1 ) ) {
					settings.activeImage = settings.activeImage + 1;
					_set_image_to_view();
					_disable_keyboard_navigation();
				}
			}
		}
		/**
		 * Preload prev and next images being showed
		 *
		 */
		function _preload_neighbor_images() {
			if ( (settings.imageArray.length -1) > settings.activeImage ) {
				objNext = new Image();
				objNext.src = settings.imageArray[settings.activeImage + 1][0];
			}
			if ( settings.activeImage > 0 ) {
				objPrev = new Image();
				objPrev.src = settings.imageArray[settings.activeImage -1][0];
			}
		}
		/**
		 * Remove jQuery lightBox plugin HTML markup
		 *
		 */
		function _finish() {
			jQuery('#jquery-lightbox').remove();
			jQuery('#jquery-overlay').fadeOut(function() { jQuery('#jquery-overlay').remove(); });
			// Show some elements to avoid conflict with overlay in IE. These elements appear above the overlay.
			jQuery('embed, object, select').css({ 'visibility' : 'visible' });
		}
		/**
		 / THIRD FUNCTION
		 * getPageSize() by quirksmode.com
		 *
		 * @return Array Return an array with page width, height and window width, height
		 */
		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth;
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else {
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){
				pageWidth = xScroll;
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		/**
		 / THIRD FUNCTION
		 * getPageScroll() by quirksmode.com
		 *
		 * @return Array Return an array with x,y page scroll values.
		 */
		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};
		 /**
		  * Stop the code execution from a escified time in milisecond
		  *
		  */
		 function ___pause(ms) {
			var date = new Date();
			curDate = null;
			do { var curDate = new Date(); }
			while ( curDate - date < ms);
		 };
		// Return the jQuery object for chaining. The unbind method is used to avoid click conflict when the plugin is called more than once
		return this.unbind('click').click(_initialize);
	};
})(jQuery); // Call and execute the function immediately passing the jQuery object
