/*
* jQuery :nth-last-child - v0.2 - 2/13/2010
* http://benalman.com/projects/jquery-misc-plugins/
* 
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
(function ($) { var c = /:(nth)-last-child(?:\((even|odd|[\dn+-]*)\))?/, a = $.expr, b = a.filter.CHILD; a[":"]["nth-last-child"] = function (h, g, e, k) { var j = e[0].match(c), f = $(h.parentNode).children(), d; j = a.preFilter.CHILD(j); b(h, j); d = f.eq(f.length - h.nodeIndex)[0]; return b(d, j) } })(jQuery);

/**
* jQuery Cookie plugin
*
* Copyright (c) 2010 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
*
*/
jQuery.cookie = function (key, value, options) {

    // key and at least value given, set cookie...
    if (arguments.length > 1 && String(value) !== "[object Object]") {
        options = jQuery.extend({}, options);

        if (value === null || value === undefined) {
            options.expires = -1;
        }

        if (typeof options.expires === 'number') {
            var days = options.expires, t = options.expires = new Date();
            t.setDate(t.getDate() + days);
        }

        value = String(value);

        return (document.cookie = [
            encodeURIComponent(key), '=',
            options.raw ? value : encodeURIComponent(value),
            options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
            options.path ? '; path=' + options.path : '',
            options.domain ? '; domain=' + options.domain : '',
            options.secure ? '; secure' : ''
        ].join(''));
    }

    // key and possibly options given, get cookie...
    options = value || {};
    var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
    return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};

var JSON = JSON || {}; 
JSON.stringify = JSON.stringify || function (obj) {
	var t = typeof (obj);
	if (t != "object" || obj === null) {
		// simple data type
		if (t == "string") obj = '"'+obj+'"';
		return String(obj);
	}
	else {
		// recurse array or object
		var n, v, json = [], arr = (obj && obj.constructor == Array);
		for (n in obj) {
			v = obj[n]; t = typeof(v);
			if (t == "string") v = '"'+v+'"';
			else if (t == "object" && v !== null) v = JSON.stringify(v);
			json.push((arr ? "" : '"' + n + '":') + String(v));
		}
		return (arr ? "[" : "{") + String(json) + (arr ? "]" : "}");
	}
};
JSON.parse = JSON.parse || function (str) {
	if (str === "") str = '""';
	eval("var p=" + str + ";");
	return p;
};

(function ($) {
    $.fn.toString = function () {
        var rS = [];
        this.each(function () { rS.push($('<span>').append($(this).clone()).remove().html()); });
        return rS.join('');
    }
})(jQuery);

function ieFix() {
    if ($.browser.msie && parseInt(($.browser.version)) <= 8) {
        $('.header .mainmenu li:last-child a').css({ 'padding-right': '47px' });
        $('.container .section .wallpapers > li:nth-child(3n+1)').css({ 'padding-left': '0' });
        $('.container .section .wallpapers > li:nth-last-child(-n+3)').css({ 'margin-bottom': '0', 'border-bottom': '0' });
        $('.container .section .wallpapers > li:nth-child(3n+3) .img').css({ 'border-right': '0' });
        $('.container .section .galleryFilters ul li:last-child a, .container .section .galleryContainer .sorting ul li:last-child a').css({ 'padding-right': '0', 'border-right': '0' });
        $('.container .section ul.galleryItems li:nth-child(4n+4)').css({ 'margin-right': '0', 'padding-right': '0', 'border-right': '0' });
        //$('.container .section ul.galleryItems li:nth-last-child(-n+4)').css({ 'padding-bottom': '3px' });
        $('.container .section ul.galleryItems.pics li:nth-child(5n+5))').css({ 'margin-right': '0', 'padding-right': '0', 'border-right': '0' });
        //$('.container .section ul.galleryItems.pics li:nth-last-child(-n+5)').css({ 'padding-bottom': '3px' });
        $('.header .mainmenu li:first-child a').css({ 'padding-left': '113px' });
     
    };
};

/* customDropdown */
(function ($) {

    String.prototype.searchFrom = function (s, f) { /* s-search regexp, f-from index */
        var tmpI = this.substr(f).search(s);
        return tmpI == -1 ? -1 : f + tmpI;
    };

    var cD2 = function (S, O) {
        this.SELECT = $(S);
        this.OPTIONS = $.extend({}, this.DEFAULTS, O);
        this.OPTS_COUNT = this.SELECT.find('option, optgroup').length;
        this.CDID = this.genCDId();
        this.NEW_ID = this.genNewId();
        this.SHOW_SCROLL = this.OPTIONS.optsScrollable && this.OPTS_COUNT > this.OPTIONS.optsCountToScroll ? true : false;
        this.OPTIONS_SHOWN = false;
        this.ID_ATTR = '[lang=' + this.CDID + ']';
        this.DISABLED = false;
        this.$LABEL = '.' + this.OPTIONS.labelClass + this.ID_ATTR;
        this.$OPTIONS = '.' + this.OPTIONS.optsClass + this.ID_ATTR;
        this.__init();
    };

    cD2.prototype = {

        DEFAULTS: {
            wrapClass: 'customDropdown',
            labelClass: 'customDropdownLabel',
            labelActiveClass: 'active',
            optsClass: 'customDropdownOptions',
            optsGrpClass: 'customDropdownOptionsGroup',
            optsGrpElemClass: 'customDropdownOptionsGroupElement',
            optSelectedClass: 'selected',
            optsScrollableClass: 'scrollable',
            optsScrollable: false,
            optsCountToScroll: 0,
            optsScrollbarWidth: 0,
            customScrollbar: true,
            optsSlideSpeed: 200, /*ms||'fast'||'slow'*/
            width: 100,
            optionHeight: 20
        },

        __init: function () {
            if (this.SELECT.parent().hasClass(this.OPTIONS.wrapClass)) { return false; }
            if ($('.' + this.OPTIONS.optsClass + '.' + this.SELECT.attr('name')).length) {
                $('.' + this.OPTIONS.optsClass + '.' + this.SELECT.attr('name')).remove();
            };
            this.OPTIONS.width = this.getWidthFromClass();
            this.DISABLED = this.SELECT.attr('disabled');
            this.buildAll();
            this.setEvents();
        },

        genCDId: function () {
            var tmpId = 'cD' + this.SELECT.index('select');
            return tmpId;
        },

        genNewId: function () {
            var orgId = this.SELECT.attr('id');
            var newId = 'cD-' + orgId;
            this.SELECT.attr('id', newId);
            return newId;
        },

        buildAll: function () {
            var _this = this;
            var wrapper = $('<div>');
            wrapper.attr({
                'id': _this.NEW_ID == 'cD-' ? _this.CDID : _this.NEW_ID,
                'class': _this.OPTIONS.wrapClass + ' ' + _this.SELECT.attr('name')
            });
            _this.SELECT.wrap(wrapper).before(_this.buildLabel());
            _this.OPTION_WIDTH_ADDITION = Math.abs(parseInt($(_this.$LABEL).children('.arrow').css('right')));
            _this.buildOptions();
        },

        buildLabel: function () {
            var _this = this;
            var tmpLabel = $('<p></p>');
            tmpLabel.attr({
                'lang': _this.CDID,
                'class': _this.OPTIONS.labelClass + ' ' + _this.SELECT.attr('class') + (_this.DISABLED ? ' disabled':''),
                'style': 'width:' + _this.OPTIONS.width + 'px'
            }).append('<span class="arrow">' + this.genLabelText() + '</span>');
            return tmpLabel;
        },

        genLabelText: function () {
            return this.SELECT.find(':selected').text();
        },

        setLabelText: function () {
            var label = $(this.$LABEL);
            label = label.children('span').length ? label.children('span') : label;
            label.text(this.genLabelText());
        },

        buildOptions: function () {
            var _this = this;
            var customDropdownOptions = $('<ul></ul>');
            customDropdownOptions.attr({
                'lang': _this.CDID,
                'class': _this.OPTIONS.optsClass + ' ' + _this.SELECT.attr('name') + (_this.SHOW_SCROLL ? ' scrollable' : ''),
                'style': 'width:' + parseInt(_this.OPTIONS.width + _this.OPTION_WIDTH_ADDITION) + 'px;' + (_this.SHOW_SCROLL ? 'height:' + (_this.OPTIONS.optsCountToScroll * _this.OPTIONS.optionHeight) + 'px;' : '')
            }).html(function () {
                var tmpHtml = [];
                _this.SELECT.children().each(function (i) {
                    tmpHtml.push(_this.buildOption($(this).text(), $(this).val(), $(this).attr('selected'), this.nodeName.toLowerCase() == 'optgroup'));
                });
                return tmpHtml.join('');
            });
            if( $('body').children('ul[lang='+_this.CDID+']').length ) $('body').children('ul[lang='+_this.CDID+']').remove();
            $('body').append(customDropdownOptions);
            _this.afterBuiltDimensionsProcessing('.' + _this.OPTIONS.optsClass+'[lang='+_this.CDID+']');
        },

        buildOption: function (text, value, selected, group) {
            var _this = this;
            var option = $('<li></li>');
            option.attr({
                'class': (selected ? 'selected' : '') + (group ? ' ' + _this.OPTIONS.optsGrpElemClass : ''),
                'rel': value,
                'style': 'width:' + (_this.OPTIONS.width - _this.OPTIONS.optsScrollbarWidth) + 'px;'
            }).text(text);
            return option.toString();
        },

        afterBuiltDimensionsProcessing: function(opts){
            $(opts).children('li').width(function(){
                return ($(this).width() - parseInt($(this).css('border-left-width')) - parseInt($(this).css('border-right-width')) - parseInt($(this).css('padding-left')) - parseInt($(this).css('padding-right')));
            });
        },

        setEvents: function () {
            var _this = this;
            $(_this.$LABEL).live('click', function () { if( !_this.DISABLED ) _this.labelClick(); });
            $(_this.$OPTIONS).find('li').live('click', function () { if( !_this.DISABLED ) _this.optionClick($(this)); });
            $(document).mouseup(function (e) { if( !_this.DISABLED ) _this.hideOptions(e); });
        },

        labelClick: function (e) {
            if (this.OPTIONS_SHOWN) {
                this.hideOptions(e);
            } else {
                this.showOptions();
            }
        },

        optionClick: function (o) {
            this.SELECT.val(o.attr('rel'));
            o.siblings('.' + this.OPTIONS.optSelectedClass).removeClass(this.OPTIONS.optSelectedClass).end().addClass(this.OPTIONS.optSelectedClass);
            this.setLabelText();
            this.hideOptions();
            this.SELECT.trigger('change');
        },

        showOptions: function () {
            var _this = this;
            _this.getLabelOffset();
            $(this.$OPTIONS).css({ 'top': _this.OFFSET.top + 'px', 'left': _this.OFFSET.left + 'px' }).slideDown(_this.OPTIONS.optsSlideSpeed, function () {
                if (_this.SHOW_SCROLL && _this.OPTIONS.customScrollbar) {
                    $(_this.$OPTIONS).jScrollPane({
                        showArrows: true
                    });
                }
            });
            $(_this.$LABEL).addClass(_this.OPTIONS.labelActiveClass);
            this.OPTIONS_SHOWN = true;
        },

        hideOptions: function (e) {
            var _this = this;
            if (!e || (!$(e.target).is('.' + _this.OPTIONS.optsClass) && !($(e.target).is(_this.$LABEL) || $(e.target).parent().is(_this.$LABEL)) && !$(e.target).parents('.jspVerticalBar').length)) {
                $(_this.$OPTIONS).slideUp(_this.OPTIONS.optsSlideSpeed, function () { $(_this.$LABEL).removeClass(_this.OPTIONS.labelActiveClass); });
                _this.OPTIONS_SHOWN = false;
            }
        },

        getLabelOffset: function () {
            this.OFFSET = $(this.$LABEL).offset();
            this.OFFSET.top += $(this.$LABEL).innerHeight();
        },

        /* pobiera szeroko?? dropdowna z klasy, jak nie ma klasy to zwraca domy?ln? z opcji */
        getWidthFromClass: function () {
            var tmpW = this.OPTIONS.width;
            var tmpSCSI = this.SELECT.attr('class').search(/width[0-9]+/);
            if (tmpSCSI > -1) {
                var tmpSCEI = this.SELECT.attr('class').searchFrom(/\ /, tmpSCSI);
                tmpSCEI = tmpSCEI == -1 ? this.SELECT.attr('class').length : tmpSCEI;
                var tmpWC = this.SELECT.attr('class').substring(tmpSCSI, tmpSCEI);
                tmpW = parseInt(tmpWC.replace(/width/, ''));
            }
            return tmpW;
        }
    };

    $.fn.customDropdown = function (options) {
        return this.each(function () {
            new cD2(this, options);
        });
    };
})(jQuery);

var _EC = {};
var EuroCounter = function (c, options) {
    this.COUNTER = c;
    this.OPTIONS = $.extend({}, this.DEFAULTS, options);
    this.TODAY = (new Date()).getTime();
    this.init();
};
EuroCounter.prototype = {
    DEFAULTS: {
        toDateYear: 2012,
        toDateMonth: 6,
        toDateDay: 8,
        toDateHour: 18,
        toDateMin: 0,
        toDateSec: 0,
        counterDays: '.days .val',
        counterHours: '.hours .val',
        counterMins: '.mins .val',
        counterSecs: '.secs .val'
    },
    init: function () {
        _EC = this;
        this.TO_DATE = new Date(this.OPTIONS.toDateYear, this.OPTIONS.toDateMonth - 1, this.OPTIONS.toDateDay, this.OPTIONS.toDateHour, this.OPTIONS.toDateMin, this.OPTIONS.toDateSec);
        this.setTimeDiff();
        this.updateCounter(this);
        $(this.COUNTER).css('visibility', 'visible');
        Cufon.replace(this.COUNTER + ' ' + this.OPTIONS.counterDays, { fontFamily: 'DIN-BoldPL' });
        Cufon.replace(this.COUNTER + ' ' + this.OPTIONS.counterHours, { fontFamily: 'DIN-BoldPL' });
        Cufon.replace(this.COUNTER + ' ' + this.OPTIONS.counterMins, { fontFamily: 'DIN-BoldPL' });
        Cufon.replace(this.COUNTER + ' ' + this.OPTIONS.counterSecs, { fontFamily: 'DIN-BoldPL' });
        /*this.startCountdown(this);*/
    },
    /*startCountdown: function () {
    if (this.TIME_DIFF <= 0) {
    clearInterval(_this.INTERVAL);
    } else {
    var _this = this;
    this.INTERVAL = setInterval(function () { _this.updateCounter(_this); }, 1000);
    }
    },*/
    updateCounter: function (_this) {
        if (this.TIME_DIFF <= 0) {
            clearInterval(_this.INTERVAL);
        } else {
            _this.setTimeDiff();
            var days, hours, mins, secs,
            timeDiffSecs = Math.floor(_this.TIME_DIFF / 1000),
            timeDiffMins = Math.floor(timeDiffSecs / 60),
            timeDiffHours = Math.floor(timeDiffMins / 60),
            timeDiffDays = Math.floor(timeDiffHours / 24);
            days = timeDiffDays;
            hours = timeDiffHours % (timeDiffDays || timeDiffHours + 1);
            mins = timeDiffMins % (timeDiffHours*60);
            secs = timeDiffSecs % (timeDiffMins);
            if (days != _this.getDays()) { _this.setDays(days); Cufon.refresh(_this.COUNTER + ' ' + _this.OPTIONS.counterDays); }
            if (hours != _this.getHours()) { _this.setHours(hours); Cufon.refresh(_this.COUNTER + ' ' + _this.OPTIONS.counterHours); }
            if (mins != _this.getMins()) { _this.setMins(mins); Cufon.refresh(_this.COUNTER + ' ' + _this.OPTIONS.counterMins); }
            if (secs != _this.getSecs()) { _this.setSecs(secs); Cufon.refresh(_this.COUNTER + ' ' + _this.OPTIONS.counterSecs); }
            setTimeout(function () { _this.updateCounter(_this); }, 1000);
        }
    },
    setTimeDiff: function () {
        this.TIME_DIFF = this.TO_DATE - (new Date()).getTime();
    },
    setDays: function (days) {
        $(this.COUNTER).find(this.OPTIONS.counterDays).text(days);
    },
    getDays: function () {
        return $(this.COUNTER).find(this.OPTIONS.counterDays).text();
    },
    setHours: function (hours) {
        $(this.COUNTER).find(this.OPTIONS.counterHours).text(hours);
    },
    getHours: function () {
        return $(this.COUNTER).find(this.OPTIONS.counterHours).text();
    },
    setMins: function (mins) {
        $(this.COUNTER).find(this.OPTIONS.counterMins).text(mins);
    },
    getMins: function () {
        return $(this.COUNTER).find(this.OPTIONS.counterMins).text();
    },
    setSecs: function (secs) {
        $(this.COUNTER).find(this.OPTIONS.counterSecs).text(secs);
    },
    getSecs: function () {
        return $(this.COUNTER).find(this.OPTIONS.counterSecs).text();
    }
};

(function ($) {
    var Fader = function(list,options){
        this.OPTIONS = $.extend({},this.DEFAULT,options);
        this.LIST = list;
        this.$LIST_ITEMS = $(this.LIST).find(this.OPTIONS.listElem);
        this.LIST_LENGTH = this.$LIST_ITEMS.length;
        this.INTERVAL = null;
        this.init();
    };
    Fader.prototype = {
        DEFAULT: {
            listElem: 'li',
            duration: 3000,
            switchSpeed: 300,
            callback: false,
            pager: false /* ul li a | ul li.active a */
        },
        init: function(){
            this.prepareList();
            this.startSwitching();
            if( this.OPTIONS.pager ) this.setPagerEvents();
        },
        prepareList: function(){
            $(this.LIST).addClass('Fader');
            this.$LIST_ITEMS.eq(0).addClass('active');
            // $('.slideContainer li').eq(0).addClass('active');
            this.ACTIVE_ITEM = 0;
        },
        startSwitching: function(){
            var _this = this;
            _this.INTERVAL = setInterval(function(){ _this.switchItems(_this); }, _this.OPTIONS.duration );
        },
        switchItems: function(_this,to){
            var to = typeof to == 'number' ? to : null;
            _this.getActiveItem().animate({
                opacity: 0
            },{
                duration: _this.OPTIONS.switchSpeed,
                queue: false,
                complete: function(){ $(this).removeClass('active');
                
                 }
            });
            _this.getNextItem(to).animate({
                opacity: 1
            },{
                duration: _this.OPTIONS.switchSpeed,
                queue: false,
                complete: function(){ 
                    if( typeof _this.OPTIONS.callback == 'function' ) _this.OPTIONS.callback(_this.ACTIVE_ITEM, _this); 
                    if( _this.OPTIONS.pager ){
                        
                       // $('.slideContainer li').removeClass('active').eq(_this.ACTIVE_ITEM).addClass('active');
                    }
                }
            });
        },
        getActiveItem: function(){
            return this.$LIST_ITEMS.eq(this.ACTIVE_ITEM);
        },
        getNextItem: function(to){
            this.ACTIVE_ITEM = to != null ? to : this.ACTIVE_ITEM == this.LIST_LENGTH-1 ? 0 : this.ACTIVE_ITEM + 1;
            return this.getActiveItem().addClass('active');
        },
        setPagerEvents: function(){
            var _this = this;
            $(_this.OPTIONS.pager).find('a').click(function(){
                if( !$(this).parent('li').hasClass('active') ){
                    clearInterval(_this.INTERVAL);
                    _this.switchItems(_this, $(this).parentsUntil(_this.OPTIONS.pager).index() );
                    _this.INTERVAL = setInterval(function(){ _this.switchItems(_this); }, _this.OPTIONS.duration );
                }
                return false;
            });
        }
    };
    $.fn.fader = function(options){
        return this.each(function(){
            new Fader(this, options);
        });
    };
})(jQuery);

function likeAlts() {
    $('.like').attr('alt', 'Nie podoba mi si&#281;');
    $('.unlike').attr('alt', 'Podoba mi si&#281;');
    $('.loggedOut').attr('alt', 'Zaloguj si&#281;');
};

function likeButtons() {
    likeAlts();
    $('span .tooltip').bind('mouseover', function () {
        $(this).before('<div class="tooltipCloud"><span class="left">' + ($(this).attr('alt') || $(this).attr('title') ) + '</span><span class="right"></span></div>');
        var y = $(this).position().top - 28;
        var x = $(this).position().left - 3;
        $('.tooltipCloud').css('top', y + 'px').css('left', x + 'px');
    });

    $('span .tooltip').bind('mouseout', function () {
        $('.tooltipCloud').remove();
    });
};

(function ($) {
    $.fn.targetBlank = function(){
        return this.each(function(){
            $(this).click(function(){
                window.open($(this).attr('href'));
                return false;
            });
        });
    };
})(jQuery);

(function($){
    var Tabs = function(t,options){
        this.$TABS = $(t);
        this.OPTIONS = $.extend({},this.DEFAULTS,options);
        this.init();
    };
    Tabs.prototype = {
        DEFAULTS: {
            naviClass: 'tabsNavi',
            naviActiveClass: 'active',
            tabActiveClass: 'active'
        },

        init: function(){
            if( this.$TABS.prev('.'+this.OPTIONS.naviClass).length ) return false;
            this.buildMenu();
            this.setNaviEvents();
        },
        buildMenu: function(){
            var _this = this;
            var tabsNavi = $('<ul class="'+this.OPTIONS.naviClass+'"></ul>');
            _this.$TABS.children('li').each(function(i){
                if( i == 0 ) $(this).addClass(_this.OPTIONS.tabActiveClass);
                tabsNavi.append('<li><a href="#"' + (i==0?' class="active"':'') + '>'+this.title+'</a></li>');
            });
             _this.$TABS.before(tabsNavi)
        },
        setNaviEvents: function(){
            var _this = this;
            this.$TABS.prev('.'+this.OPTIONS.naviClass).children('li').each(function(){
                var _li = $(this);
                $(this).children('a').click(function(){ 
                    _this.toggleTabs(_li.index()); 
                    $(this).parent('li').siblings().children('.'+_this.OPTIONS.naviActiveClass).removeClass(_this.OPTIONS.naviActiveClass);
                    $(this).addClass(_this.OPTIONS.naviActiveClass);
                    return false; 
                });
            });
        },
        toggleTabs: function(i){
            this.$TABS.children('li:not(:eq('+i+'))').removeClass(this.OPTIONS.tabActiveClass).hide();
            this.$TABS.children('li:eq('+i+')').addClass(this.OPTIONS.tabActiveClass).show();
            equalGroups();
        }

    };
    $.fn.tabs = function(options){
        return this.each(function(){
            new Tabs(this,options);
        });
    };
})(jQuery);

/* pobieranie zdj?? dla galerii 2010 z odpowiednich podstron */
var PicsGetter = function (options) {
    this.options = $.extend({}, this.defaults, options);
    this.init();
};
PicsGetter.prototype = {
    defaults: {
        galleryContainer: '.pics ul.galleryItems',
        pageList: 'select[name=pageList]',
        pageListEvent: 'change',
        pageListElements: false,
        pageListElementsEvent: false,
        loader: false,
        singlePageURL: '/Zdjecie2010.aspx'
    },
    init: function () {
        this.setEvents();
        $(this.options.pageList).children('option')[0].selected = 'selected';
        this.pageUrl = $(this.options.pageList).children('option')[0].value;
        this.getPicsPage(this.pageUrl);
    },
    getPicsPage: function () {
        var _this = this;
        if (_this.options.loader) {
            $.ajaxStart(function () {
                //TODO loader
            });
        };
        $.ajax({
            url: _this.pageUrl,
            success: function (d, t, x) {
                _this.parsePicsPage(d);
            }
        });
    },
    parsePicsPage: function (page) {
        var _this = this;
        $(_this.options.galleryContainer).html(page);
        $(_this.options.galleryContainer).children('li').each(function () {
            _this.setPicsLinks(this.childNodes[0]);
        });
    },
    setEvents: function () {
        var _this = this;
        if (!_this.options.pageListElements) {
            $(_this.options.pageList).bind(_this.options.pageListEvent, function () {
                _this.pageUrl = this.value;
                _this.getPicsPage();
            });
        };
        if (_this.options.loader) {
            $(_this.options.galleryContainer).delegate('img', 'load', function () {
                //;
            });
        };
        $(_this.options.galleryContainer).delegate('a', 'click', function () {
            _this.preparePageParams(this);
            return true;
        });
    },
    setPicsLinks: function (pic) {
        var _this = this;
        $(pic).attr({
            'rel': function () {
                return pic.href;
            },
            'href': function () {
                return _this.options.singlePageURL;
            }
        });
    },
    preparePageParams: function (pic) {
        var params = {
            itemIdx: $(pic).parent('li').index(this.options.galleryContainer + ' li'),
            categoryUrl: encodeURIComponent(this.pageUrl)
        };
        var cookieValue = JSON.stringify(params);
        $.cookie('cccPPP', cookieValue, { path: '/' });
    }

};

(function ($) {
    $.fn.inputWrap = function(){
        return this.each(function(){
            if( $(this).parent('span.inputTextWrapper').length ) return;
            $(this).wrap('<span class="inputTextWrapper"></span>');
        });
    };
})(jQuery);

(function ($) {

    $.fn.userDataSwitch = function(){

        var checkIfPlayer = function(radio){
            if( $(radio).is(':checked') ){
                if( radio.value == '1' ){
                    $('span.team').text('Twoja');
                    $('#liPlayerPosition').show();
                }else if( radio.value == '2' ){
                    $('span.team').text('Ulubiona');
                    $('#liPlayerPosition').hide();
                };
            };
        };

        return this.each(function(){
            checkIfPlayer(this);
            $(this).change(function(){
                checkIfPlayer(this);
            });
        });
    };

})(jQuery);

var cufonSetup = [
    {
        selector: '.header .mainmenu li a',
        fontStyle: { fontFamily: 'DIN-RegularPL', textShadow: '#555 1px 1px' }
    },
    {
        selector: '.header .mainmenu li.fbzwyciezcy',
        fontStyle: { fontFamily: 'DIN-RegularPL', textShadow: '#555 1px 1px' }
    },
    {
        selector: '#euro2012Counter h2 span:not(.euroLogo)',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: 'div.homepage .mainBox h2',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: 'div.homepage .mainBox:not(.forumBox) h3',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '#euro2012Counter ul li .unit',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '.content.homepage h2.headline',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '#newsbox ul li .newsTxt h3',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '.container .section .selectedContent .gamesInfo',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '.container .section .galleryContainer p.noPics',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '.container .section .galleryContainer p.noMovies',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '.content.messages .noMessages',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '.flagBox h3',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '#newsbox ul li h3 a',
        fontStyle: { fontFamily: 'DIN-BoldPL', textShadow: '#555 1px 1px' }
    },
    {
        selector: '#jakDolaczyc h3',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '#steps li',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    },
    {
        selector: '#jakDolaczyc .box570 p',
        fontStyle: { fontFamily: 'DIN-RegularPL' }
    }, 
    {
        selector: '#jakDolaczyc .box570 p.note',
        fontStyle: { fontFamily: 'DIN-BoldPL' }
    }
];

function applyCufon() {
    for(c in cufonSetup){
        if ($(cufonSetup[c].selector).length) Cufon.replace(cufonSetup[c].selector, cufonSetup[c].fontStyle);
    };
    Cufon.now();
};

function refreshCufon() {
    for(c in cufonSetup){
        if( $(cufonSetup[c].selector).length ) Cufon.refresh(cufonSetup[c].selector);
    };
};

function applyScripts() {
   


    new EuroCounter('#euro2012Counter ul', {});
    $('.homepage .mainBox.partnersBox ul').fader();
    $('#newsbox ul:not(.newsboxPager)').fader({
        duration: 10000,
        pager: '#newsbox .newsboxPager'
    });

    swfobject.embedSWF("_flash/promo_2011.swf", "academyFlash", "170", "210", "10.0", "_swf/expressInstall.swf", {}, { wmode: "opaque" }, { id: "academyFlash", name: "academyFlash" });

    var flashvars = {
        current: new Date().getTime()/1000,//'1297842895', //aktualny czas w sekundach
        target: '1298037600' //docelowy czas w sekundach	
    };

    swfobject.embedSWF('/_flash/cc_cup_counter.swf', 'regCounter', '170', '210', "9.0.0", '/_flash/expressInstall.swf', flashvars, {}, {});

    likeAlts();

    $('.tooltip').bind('mouseover', function () {
        $(this).before('<div class="tooltipCloud"><span class="left">' + ($(this).attr('alt') || $(this).attr('title')) + '</span><span class="right"></span></div>');
        var y = $(this).position().top - 28;
        var x = $(this).position().left - 3;
        $('.tooltipCloud').css('top', y + 'px').css('left', x + 'px');
    });

    $('.tooltip').bind('mouseout', function () {
        $('.tooltipCloud').remove();
    });


    if ($('ul.tabs').length) $('ul.tabs').tabs();
    if ($('.pics2010 .galleryItems').length) { new PicsGetter(); };


    $('select').customDropdown({ scrollable: false });
    $('input[type=text]').inputWrap();

    $('.isPlayer input').userDataSwitch();

    if ($('.errorMsg').length) $('.errorMsg').removeClass('errorMsg').addClass('errorMsgWrapper').wrapInner('<span class="errorMsg"></span>');

    ieFix();
    applyCufon();
    $('a[href$=".pdf"], a.blank').targetBlank();
};

function equalGroups() {
    $('ul.teams li.group:even ul.tabs').each(function () {
        $(this).css('height', 'auto');
        $(this).parent().css('height', 'auto');
        $(this).parent().next().find('ul.tabs').css('height', 'auto');
        $(this).parent().next().css('height', 'auto');

        var even = $(this).height();
        var odd = $(this).parent().next().find('ul.tabs').height();
        if (even > odd) {
            $(this).height(even + 'px');
            $(this).parent().next().find('ul.tabs').height(even + 'px');            
        } else if (even < odd) {
            $(this).height(odd + 'px');
            $(this).parent().next().find('ul.tabs').height(odd + 'px');
        }

        var even = $(this).parent().find('.fInfo').outerHeight();
        var odd = $(this).parent().next().find('.fInfo').outerHeight();
        if (even > odd) {
            $(this).parent().find('.fInfo').height(even + 'px');
            $(this).parent().next().find('.fInfo').height(even + 'px');
        } else if (even < odd) {
            $(this).parent().find('.fInfo').height(odd + 'px');
            $(this).parent().next().find('.fInfo').height(odd + 'px');
        }

        var even = $(this).parent().height();
        var odd = $(this).parent().next().height();
        if (even > odd) {
            $(this).parent().height(even + 'px');
            $(this).parent().next().height(even + 'px');
        } else if (even < odd) {
            $(this).parent().height(odd + 'px');
            $(this).parent().next().height(odd + 'px');
        }
    });
}

function equalLines() {
    $('.treeFirstBranch .treePair').each(function () {
        var t1 = $(this).find('.treeTeam:nth-child(1)').outerHeight();
        var t1half = t1 / 2;
        var t2half = $(this).find('.treeTeam:nth-child(2)').outerHeight() / 2;
        var margin = 35;
        $(this).find('.lines').css({ 'top': t1half + 'px', 'height': t1half + t2half + margin + 'px' });
        $(this).find('.treeScore').css({ 'top': t1 + 'px' });
    });
    $('.treeSecondBranch .treePair').each(function () {
        var index = $(this).index();
        var h = $('.treeFirstBranch .treePair').eq(index * 2).outerHeight(0) + $('.treeFirstBranch .treePair').eq(index * 2 + 1).outerHeight() + 20;
        var m1 = $('.treeFirstBranch .treePair').eq(index * 2).find('.treeScore').position().top;
        var dif1 = (35 - $(this).find('.treeTeam:nth-child(1)').outerHeight()) / 2;
        m1 += dif1;
        var m2 = $('.treeFirstBranch .treePair').eq(index * 2 + 1).find('.treeTeam:nth-child(2)').outerHeight();
        var dif2 = (35 - $(this).find('.treeTeam:nth-child(2)').outerHeight()) / 2;
        m2 += dif2;
        $(this).css({ 'height': h + 'px' })
        $(this).find('.treeTeam:nth-child(1)').css({ 'top': m1 + 'px' });
        $(this).find('.treeTeam:nth-child(2)').css({ 'bottom': m2 + 'px' });

        var t1 = $(this).find('.treeTeam:nth-child(1)').outerHeight();
        var t1half = t1 / 2;
        var t2 = $(this).find('.treeTeam:nth-child(2)').outerHeight() / 2;
        var t2half = t2 / 2;
        var margin = h - t1 - t2 - m1 - m2;
        $(this).find('.lines').css({ 'top': t1half + m1 + 'px', 'height': t1half + margin + 'px' });
        var lh = $(this).find('.lines').outerHeight();
        $(this).find('.treeScore').css({ 'top': m1 + t1half + ((lh - 35) / 2) + 'px' });
    });
    $('.treeThirdBranch .treePair').each(function () {
        var index = $(this).index();
        var h = $('.treeSecondBranch .treePair').eq(index * 2).outerHeight(0) + $('.treeSecondBranch .treePair').eq(index * 2 + 1).outerHeight() + 20;
        var m1 = $('.treeSecondBranch .treePair').eq(index * 2).find('.treeScore').position().top;
        var dif1 = (35 - $(this).find('.treeTeam:nth-child(1)').outerHeight()) / 2;
        m1 += dif1;
        var m2 = ($('.treeSecondBranch .treePair').eq(index * 2 + 1).find('.treeTeam:nth-child(2)').outerHeight() / 2) + parseFloat($('.treeSecondBranch .treePair').eq(index * 2 + 1).find('.treeTeam:nth-child(2)').css('bottom')) + ($('.treeSecondBranch .treePair').eq(index * 2 + 1).find('.lines').outerHeight() / 2) - 20;
        var dif2 = (35 - $(this).find('.treeTeam:nth-child(2)').outerHeight()) / 2;
        m2 += dif2;
        $(this).css({ 'height': h + 'px' })
        $(this).find('.treeTeam:nth-child(1)').css({ 'top': m1 + 'px' });
        $(this).find('.treeTeam:nth-child(2)').css({ 'bottom': m2 + 'px' });

        var t1 = $(this).find('.treeTeam:nth-child(1)').outerHeight();
        var t1half = t1 / 2;
        var t2 = $(this).find('.treeTeam:nth-child(2)').outerHeight() / 2;
        var t2half = t2 / 2;
        var margin = h - t1 - t2 - m1 - m2;
        $(this).find('.lines').css({ 'top': t1half + m1 + 'px', 'height': t1half + margin + 'px' });
        var ts = m1 + t1 + ((margin - 35) / 2);
        $(this).find('.treeScore').css({ 'top': ts + 'px' });

    });
    $('.tree_stages .winner').each(function () {

        var ts = $(this).parent().find('.treeScore').position().top;
        var wh = $(this).find('.treeTeam').outerHeight();
        wh = (35 - wh) / 2
        $(this).css({ 'top': ts + wh});
    });

}

function dropDownLoader() {

    $('select.dropRegion').change(function () {
        $('.totalResults').hide();
        $('.loader').show();        
    });
    $('select.dropRound').change(function () {
        if ($(this).val() == '15' || $(this).val() == '16' || $(this).val() == '3' || $(this).val() == '4') {
            $('.totalResults').hide();
            $('.loader').show();
        }
    });
    $('select.dropStage').change(function () {
        if ($('p.dropRegion').text() != '-- Wybierz -- ' && $('p.dropRegion').text() != 'Wybierz') {
            $('.totalResults').hide();
            $('.loader').show();
        }
    });
    
}

function rotator() {

    var slideWidth = 161;
    var sliderWidth = ($('.slideContainer .slide').length - 1) * slideWidth;
    var leftMargin = Number($('.slideContainer').css('left').replace('px', ''));
    var thisLeft;
    $('.slideContainer').css('width', sliderWidth);

    $('#slider ul li').each(function () {

        thisLeft = $(this).css('left');
        if (thisLeft == '-161px') {
            $(this).css('left', '483px');
        }

    })
    $('.slideContainer li').animate({
        left: '-=' + slideWidth
    }, 1000, function () {
        // Animation complete.

    });

    setTimeout('rotator()', 5000);
    
}

$(document).ready(function () {
    applyScripts();
    Sys.Application.add_load(function (source, args) {
        likeButtons();
        $('select').customDropdown({ scrollable: false });
        if ($('ul.tabs').length) $('ul.tabs').tabs();
        ieFix();
        refreshCufon();
    });


    $('#slider ul li').eq(0).css('left', '0');
    $('#slider ul li').eq(1).css('left', '161px');
    $('#slider ul li').eq(2).css('left', '322px');
    $('#slider ul li').eq(3).css('left', '-161px');
    $('#slider ul li').show();
    $('#slider ul li').eq(4).hide();





    setTimeout('rotator()', 5000);


});

$(function () {

    // Konkurs wnies flage
    //toltip zaloguj sie
    $('.showTooltip, .tooltipLogin').hover(function () {
        if ($(this).find('.noActiveVote').length > 0) {
            $('.tooltipLogin').show();
        }
    }, function () {
        $('.tooltipLogin').hide();
    })
});

window.onload = function () {
    $('body form').css('display', 'block');
    //  $('.scroll-pane').jScrollPane();
    if ($('.timeRight').length > 0) $('.timeRight .scroll-pane').jScrollPane();
    $('body').addClass('bg');

  
};




