var JS = {
	controller: '',
	action : '',

	init: function(){		

		$("a[rel^='prettyPhoto']").prettyPhoto();

        $('.lightBox img').hover(function(){
            $(this).fadeTo(400, 0.6);
        }, function() {
            $(this).fadeTo(400, 1);
        });

        //Set Cofon
        Cufon.replace('h1', { hover: true, hoverables: { h1: true } });
        Cufon.replace('h2', { hover: true, hoverables: { h2: true } });
        Cufon.replace('h3', { hover: true, hoverables: { h3: true } });
        Cufon.replace('h4', { hover: true, hoverables: { h4: true } });
        Cufon.replace('h5', { hover: true, hoverables: { h5: true } });
        Cufon.replace('h6', { hover: true, hoverables: { h6: true } });
        Cufon.replace('#intro p');
        Cufon.replace('#mainMenu li a', { hover: true, hoverables: { a: true } });

		JS.newsletterSignin();

		$("#carousel").moodular();
	},
	//-----------------------
	inputDescription: function(){
		var aInputs = new Array();var iCount = 0;
		$('input.value').each(function(){
			aInputs[iCount] = $(this).val();
			$(this).attr('rel', 'input_id_'+iCount);
			iCount++;
		});
		
		var iId = 0;
		$('input.value').focus(function(){
			iId = $(this).attr('rel').replace('input_id_','');
			if($(this).val() === aInputs[iId]){
				$(this).val('');
			}
		}).blur(function(){
			iId = $(this).attr('rel').replace('input_id_','');
			if('' === $(this).val()){
				$(this).val(aInputs[iId]);
			}
		});
	},
	//-----------------------
	addToFavourite: function(){
		 if (window.sidebar) { // Mozilla Firefox 
		          window.sidebar.addPanel(document.title,location.href,'');
		} else if (window.external) { // IE 
			window.external.AddFavorite(location.href,document.title); 
		} else if (window.opera && window.print) { 
			window.external.AddFavorite(location.href,document.title); 
		} else { 
			alert("Twoja przeglądarka nie obsługuje tej funkcji"); 
		} 
	},
	//----------------------
	displayBanners: function(){
		
		$('.zone').each(function(){
			var id = $(this).attr('id').replace('zone_','');
			$.ajax({
				url: WEB_HOST+'ajax,zone,id,'+id,
				success: function(data){
					if('swf' == data.ext){ 
						    swfobject.embedSWF(WEB_HOST+'uploads/banery/'+data.filepath, 'zone_'+id, data.width, data.height, "9.0.0");
					}else{
						$('#zone_'+id).html(
							'<a href="'+data.url+'" target="_blank"><img alt="" src="'+WEB_HOST+'uploads/banery/'+data.filepath+'" /></a>'
						);
					}
				},
				cache: false,
				dataType: "json"
			});
		});
	},
	//----------------------
	newsletterSignin: function(){
		$('#newsletterSignin').submit(function(){

			$.ajax({
				url: WEB_HOST+'ajax,newsletter',
				data: $(this).serialize(),
				success: function(data){
					if('ok' == data.type){
						$('#newsletter_email').val('');
					}
					alert(data.message);
				},
				type: "POST",
				dataType: "json"
			});


			return false;

		});
	}
	//----------------------
};

$(document).ready(function(){

	JS.init();

	if(window[JS.controller] != undefined){
		if(typeof window[JS.controller]['init'] == 'function'){
			window[JS.controller]['init']();
		}
		if(typeof window[JS.controller][JS.action] == 'function'){
			window[JS.controller][JS.action]();
		}
	}

})

