/*
* Author:      Marco Kuiper (http://www.marcofolio.net/)
*/

jQuery(function(ready){

	
		// Set the Z-Index (used to display images on top while dragging)
		var zindexnr = 20;
		
		// boolean to check if the user is dragging
		var dragging = false;
		
		// Show the polaroid on top when clicked on
		$("#nowosciOferta .floatbox").mouseup(function(e){
		
			if(!dragging) {
				// Bring polaroid to the foreground
				zindexnr++;
				var cssObj = { 'z-index' : zindexnr
	    };
	      $(this).css(cssObj);
				
			}
		});
		
		// Make the polaroid draggable & display a shadow when dragging
		$("#nowosciOferta .floatbox").draggable({
		
			containment: 'parent',
			cursor: 'crosshair',
			start: function(event, ui) {
			
				dragging = true;
				zindexnr++;
				var cssObj = {/* 'box-shadow' : '#888 3px 4px 4px', // added in case CSS3 is standard
					'-webkit-box-shadow' : '#888 3px 4px 4px', // safari only
					'-moz-box-shadow' : '#888 3px 4px 4px', // firefox only
					*/
					'z-index' : zindexnr };
				$(this).css(cssObj);
			},
			stop: function(event, ui) {
	
				var cssObj = { 'box-shadow' : '', // added in case CSS3 is standard
					'-webkit-box-shadow' : '', // safari only
					'-moz-box-shadow' : '', // firefox only
					'margin-left' : '0px',
					'margin-top' : '0px' };
				$(this).css(cssObj);
				dragging = false;
				}
		});
	$('#abelard_newsletter_mail').focus(function(){
		if ($(this).attr('value') == 'Tu wpisz swój adres e-mail' || $(this).attr('value') == 'type your e-mail adress')
		{
			$(this).attr('value','');
		}	
	});
	$('#abelard_newsletter_mail').blur(function(){
		if ($(this).attr('value') == '')
		{
			if (language == 'en')
			{
				$(this).attr('value','type your e-mail adress');
			}else{
				$(this).attr('value','Tu wpisz swój adres e-mail');
			}
		}	
	});
	$("#DodajEmail").click(function(){
		value = $('#abelard_newsletter_mail').attr('value');
		if ( value != '' && value != 'type your e-mail adress' && value != 'Tu wpisz swój adres e-mail' )
		{
			$("#addMailForm").submit();	
		}else {
			return false;
		}	
		//return false;
	});
	$(".return").click(function() {
		history.back();
		return false;
	});
	
	$(document).ready(function(){	
	    $('#Items').selectbox();//show categories in searching
			showdetails();//show levels in top menu
	        tabnav();//show hide pane
	        mainmenu();
	});
	$("#searchButton").click(function(){
		$("#searchForm").submit();
		return false;
	});
	$(".notepad").click(function(){
		href = $(this).attr('href');
		$.ajax({ 
			type: "POST",
			url: href,
			beforeSend: function(html)
			{ 
				jQuery.blockUI({  
					message: '<div>Proszę czekać...</div>', 		   
					fadeIn: 400, 
					fadeOut: 400, 
					showOverlay: false, 
					centerY: false, 
					css: { 
						width: '150px',
						top: '300px', 
						left: '400px', 
						border: 'none', 
						padding: '5px', 
						backgroundColor: '#000', 
						'-webkit-border-radius': '5px', 
						'-moz-border-radius': '5px', 
						opacity: '.6', 
						color: '#fff',
						cursor: 'wait'		
					} 
				});
			}, 

			success: function(html)
			{ //so, if data is retrieved, store it in html
				param = html.split('_');
				html = param[0];
				params = href.split('/');
				id = params[params.length - 1];
				if (html == "zapisano")
				{
					obj = $("a[href='"+href+"']");
					img = $("a[href='"+href+"'] img");
					/*obj.attr('href','/'+language+'/notatnik/usun/'+id);
					obj.attr('title','Usuń ofertę z notesu');
					img.attr('src','/images/usun_z_notesu.gif')
					*/
					obj.attr('href','#');
					img.attr('src','/images/oferta_w_notesie_ico.png');
					img.attr('title','Oferta w notesie');
					img.attr('alt','Oferta w notesie');
					$("#menu_notepad").attr('class','notes_plus');
					img.insertBefore(obj);
					obj.hide();
					$("#message_info").html('Dodano ofertę <font class="green">'+param[1]+'</font> do notesu.');
				}
				if (html == 'skasowano')
				{
					obj = $("a[href='"+href+"']");
					img = $("a[href='"+href+"'] img");
					if (obj.attr('class') != 'notepad delete')
					{
						obj.attr('href','/'+language+'/notatnik/dodaj/'+id);
						obj.attr('title','Dodaj ofertę do notesu');
						img.attr('src','/images/dodaj_do_notesu_ico.png')
					}else {
						$("#_"+ id).remove();
					}
					$("#message_info").html('Usunięto ofertę <font class="green">'+param[1]+'</font> z notesu.');
					
				}	
				$("#message_window").show();
				setTimeout(jQuery.unblockUI, 5);
			} 
		});
		return false;
	});
	
	$("#message_close").click(function(){
		$("#message_window").hide();
		return false;
	});
	$("#Items_input").click(function(){
		$("#Items_input_").text('wszystkie');
	});
	
});

