/* www.nyloncoffee.pl */
document.write('<script type="text/javascript" src="/panel/script/debugger.js"></script>');
document.write('<script type="text/javascript" src="/sklep/script/scroll.js"></script>');
document.write('<script type="text/javascript" src="/sklep/script/jquery-1.4.1.min.js"></script>');
document.write('<script type="text/javascript" src="/sklep/script/jquery-cookie-1.0.min.js"></script>');
document.write('<script type="text/javascript" src="/sklep/script/jquery.lightbox-0.5.min.js"></script>');
document.write('<script type="text/javascript" src="/sklep/script/swfobject.js"></script>');

if(typeof(ie6)!='boolean')
	var ie6 = false;

window.onload = function()
{
	Scroll.init();
}

String.prototype.repeat = function(i)
{
	return (new Array(i+1)).join(this);
}

function MyLoad() { try {

	swfobject.embedSWF('/sklep/flash/intro.swf','flash-intro','980','246', '9.0.0.0', '', {link_0:'/'});

	/* intro */
	if((document.referrer.indexOf(window.location.hostname)<0 && window.location.pathname==='/') || (window.location.pathname==='/' && !$.cookie('intro')) || window.location.pathname.indexOf('intro')>0)
	{
		$.cookie('intro',1);
		$('body > *').hide();
		$('#intro').show().height($(window).height());
		if(window.location.pathname==='/')
		$('#intro .item:eq(0) a').click(function(){
			$('body > div').show();
			$('#intro').fadeOut('slow',function(){ $(this).remove(); });
			return false;
		});
	}

	/*
	 * Change selection in HTMLSelectElement
	 * @example: $('select').selectValue(valueToSelect);
	 * @param: string|numeric val <option value="valueToSelect">
	 * @return: JQuery
	 */
	$.fn.extend({ selectValue: function(val){
		var selectElement = this[0];
		if(selectElement instanceof HTMLSelectElement)
			$.each(selectElement.options,function(index,optionElement){
				if(optionElement instanceof HTMLOptionElement && optionElement.value==val)
					selectElement.selectedIndex = index;
			});
		return this;
	}});

/*
	$('a').each(function(i){
		if(this.rel=='decodeString')
			{ if(this.href.indexOf(this.innerHTML)>-1) { while(this.firstChild!=null) this.removeChild(this.firstChild); this.appendChild(document.createTextNode(stringEncode(this.href.substring(6,this.href.length)))); this.href = 'mailto:'+this.innerHTML; } else this.href = 'mailto:'+stringEncode(this.href.substring(6,this.href.length)); }
		else if (this.rel=='external') { this.setAttribute('target','_blank'); };
	});
*/
	$('a[rel~=external]').attr('target','_blank');
	$('a[rel~=lightbox]').lightBox({ imageBlank: '/sklep/images/lightbox-blank.gif', imageLoading: '/sklep/images/lightbox-ico-loading.gif', imageBtnClose: '/sklep/images/lightbox-btn-close.gif', imageBtnPrev: '/sklep/images/lightbox-btn-prev.gif', imageBtnNext: '/sklep/images/lightbox-btn-next.gif', txtImage: 'Zdjęcie', txtOf: 'z' });

	$('input').each(function(i)
	{
		if($(this).hasClass('swaptitle'))
		{
			$(this).bind({
				focus: function()
				{
					if($(this).val()==$(this).attr('title'))
						$(this).val('');
				},
				blur: function()
				{
					if($(this).val()=='')
						$(this).val($(this).attr('title'));
				}
			});
			$(this).trigger('blur'); 
		};
	});

	$('#gallery_image a').each(function(){
		$(this).data('title',$(this).attr('title'));
	});

	$('.gallery_container a').unbind('click').click(function(){

		var sourcePath = $(this).attr('href');
		var sourceTitle = $(this).attr('title');
		var destImg = $('#gallery_image img').css('opacity','0.5');

		$('#prod_vopt_1').selectValue($(this).attr('rel').replace(/^[^\d]+/,''));

		$.ajax({
			data: { w: $(destImg).width(), h: $(destImg).height(), f: sourcePath },
			dataType: 'xml',
			type: 'GET',
			url: '/resizeimage.xml',
			success: function(oXML, textStatus, XMLHttpRequest)
			{
				var path = $('result',oXML).text();
				if(path!='false')
					$('#gallery_image a').each(function(){
						$(this).attr('title',$(this).data('title')+'. '+sourceTitle).attr('href',sourcePath).empty().append('<img src="'+path+'" alt="" />')
					});
				if(window.location.href.indexOf('#')>0)
					window.location.href = window.location.href.substring(0,window.location.href.indexOf('#'))+'#ptop';
				else
					window.location.href = window.location.href+'#ptop';

				$(destImg).css('opacity','1');
			}
		});

		return false;
	});

	$('#menu_bottom a').click(function(){
		$($(this).attr('href').substring($(this).attr('href').indexOf('#'))).each(function(){
			if(!$(this).next('dd').hasClass('visible'))
				$(this).click();
		});
		return true;
	});

	if($('#documentlist dd').length>1)
	{
		$('#documentlist dd').hide();
		$('#documentlist dt').click(function()
		{
			window.location.hash = $(this).attr('id');
			if($(this).next('dd').hasClass('visible'))
				$(this).next('dd').slideUp();
			else
				$(this).next('dd').slideDown();
			$(this).next('dd').toggleClass('visible');
		});
		$('#documentlist dd .slideup').click(function()
		{
			$(this).parents('dd').prev('dt').trigger('click');
		});
		/* expand the one selected in uri#hash */
		$(window.location.hash).click();
	};

	$('.extended_search dd').hide();
	$('.extended_search dt').click(function()
		{
			if($(this).next('dd').hasClass('visible'))
				$(this).next('dd').slideUp();
			else
				$(this).next('dd').slideDown();
			$(this).toggleClass('visible');
			$(this).next('dd').toggleClass('visible');
		});
	$('.extended_search dt:eq(0)').trigger('click');

} catch(err) { alert(err); } };

function stringEncode(string) { var sReturn = ''; var aChar = string.split('.'); for(var i=0,j=aChar.length;i<j;++i) sReturn += String.fromCharCode(parseInt(aChar[i])); return sReturn; }
function setLocation(l) { window.location = l; }

