/*
 * LightWindow v 0.1 beta
 * Skrypt LightWindow wymaga frameworka jquery w wersji 1.3.2 lub wyższej
 * Autor: Michał Pakuła
 * www.requiem.wroclaw.pl
 */

 function lightwindow(location){
	var index=$('#lightwindow').index();
	if (index<0) {
		$('body').append('<div id="lightwindow_back"><div id="lightwindow"></div><div id="lw_loading"></div></div>');
		$('body').append('<script type="text/javascript">$(function(){ $(\'#lightwindow\').mouseout(function(){ $(\'#lightwindow_back\').click(function(event){ var target=$(event.target).attr(\'id\'); if (target==\'lightwindow_back\') {	$(\'#lightwindow\').fadeOut(\'300\'); $(\'#lightwindow_back\').fadeOut(\'300\');	 } }); }); });</script>');
	}
		$.ajax({
			type: 	"GET", 
			url: 	location, 
			data: 	"ajax=1", 
			beforeSend: function(){
				$('#lightwindow_back').fadeIn('500');
				$('#lw_loading').show();
				$("#lightwindow").html('<a href="#" id="wl_close">X</a>');
				$('#wl_close').click(function(){
					$(this).parents("#lightwindow").fadeOut('300');
					$(this).parents("#lightwindow_back").fadeOut('300');
					return false;
				});;
			},
			success: function(html){
				$("#lightwindow").append(html);
				$('#lw_loading').fadeOut('100');
				$("#lightwindow").fadeIn('200');
			},
			error: function(){
				$('#lw_loading').fadeOut();
				$("#lightwindow").html('<blockquote>Wystąpił błąd podczas pobierania strony, prosimy spróbować ponownie.</blockquote>');
				setTimeout(function(){						//Ostrożnie!!!
					$('#lightwindow_back').fadeOut('500')
					},3000
				);
			}
		});
		return false;
 };
 
 /* #################################### */
 


 
 /* #################################### */
 /**
 * Cookie plugin
 *
 * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
 * Dual licensed under the MIT and GPL licenses:
 * http://www.opensource.org/licenses/mit-license.php
 * http://www.gnu.org/licenses/gpl.html
 *
 */

/**
 * Create a cookie with the given name and value and other optional parameters.
 *
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Set the value of a cookie.
 * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
 * @desc Create a cookie with all available options.
 * @example $.cookie('the_cookie', 'the_value');
 * @desc Create a session cookie.
 * @example $.cookie('the_cookie', null);
 * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
 *       used when the cookie was set.
 *
 * @param String name The name of the cookie.
 * @param String value The value of the cookie.
 * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
 * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
 *                             If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
 *                             If set to null or omitted, the cookie will be a session cookie and will not be retained
 *                             when the the browser exits.
 * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
 * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
 * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
 *                        require a secure protocol (like HTTPS).
 * @type undefined
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */

/**
 * Get the value of a cookie with the given name.
 *
 * @example $.cookie('the_cookie');
 * @desc Get the value of a cookie.
 *
 * @param String name The name of the cookie.
 * @return The value of the cookie.
 * @type String
 *
 * @name $.cookie
 * @cat Plugins/Cookie
 * @author Klaus Hartl/klaus.hartl@stilbuero.de
 */
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

 
 
 /* #################################### */

$(function(){	
	

/**
 * @author Alexander Farkas
 * v. 1.02
 */
	$.extend($.fx.step,{
	    backgroundPosition: function(fx) {
            if (fx.state === 0 && typeof fx.end == 'string') {
                var start = $.curCSS(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
			}
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];

           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9\.]+)(\s|\)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9\.]+)(px|\%|em|pt)\s(-?[0-9\.]+)(px|\%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
	});


	//sekcja onLoad:
	$("#bodyroot").css('display','none').fadeIn(1200);
	
	$("a.lightbox").lightBox();
	
	
	//showplayer
	$('#showplayer').click(function(){
		var link=$(this).attr('href');
		var playerwin=window.open(link,'Requiem - player','height=420,width=320,scrollbars=0,location=0,status=0,resizable=0');
		  playerwin.moveTo(40,100);
		$(this).blur();
		return false;
	});
	
	//topmenu
	$("li.shader").css( {backgroundPosition: "0 0"} )
	$("li.shader").mouseover(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 -60px)"}, 
			{duration:500})
		})
	$("li.shader").mouseout(function(){
		$(this).stop().animate(
			{backgroundPosition:"(0 0)"}, 
			{duration:500})
		})
	//top-pod-menu
	$("li.xtended ul").each(function(){
		var h=$(this).height();
		$(this).attr('rel',h).height('0').css('overflow','hidden');
	});
	$("li.xtended").mouseenter(function(){
			var h=$(this).find('ul').attr('rel');
			$(this).find('ul').stop().animate({ height: h}, 500);
		})
	$("li.xtended").mouseleave(function(){
			$(this).find('ul').stop().animate({ height: '0' }, 500);
		})
		
	
	//Zespół-Slider
	$('#zespol_slider').css('overflow','hidden');
	$("#zespol_slider_menu li a").click(function(){
		var id=$(this).attr('class');
		var pos=$(this).attr('rel');
		$('#zespol_slider').animate( { scrollLeft: pos }, 800, "swing");
		$(this).blur();
		window.location.hash=id;
		return false;
	});
	
	
	//Be-social!
	var be_social_hide;
	if($.cookie('was_today')) { 				//pokaujemy na starcie raz dziennie
		$('#be_social').css('right','-305px');
	} else {
		$('#be_social').css('display','none').slideDown(1000);
		be_social_hide=setTimeout(function(){
			$('#be_social').animate({right:'-305px'},1200);
		},10000);
		$.cookie("was_today", "1", { expires: 0.75 });
	}
	$('#be_social').hover(function(){			//obsługa zasadnicza
		clearTimeout(be_social_hide);
		be_social_hide=setTimeout(function(){
			$('#be_social').stop().animate({right:'0'},700);
		},150);
	},function(){
		be_social_hide=setTimeout(function(){
			$('#be_social').stop().animate({right:'-305px'},1200);
		},500);
	});
	$('#be_social a').hover(function(){		//wyświetlanie etykiet
		var name=$(this).text();
		var be_soc_pos=$('#be_social').css('right');
		if (be_soc_pos=='0px' || be_soc_pos=='0') $('#be_social_ad').text(name).stop().animate({opacity:'0.75'},400);
	},function(){
		$('#be_social_ad').stop().animate({opacity:'0'},400);
	});

	
});

