﻿/*** Galeria dla zdjec w widoku galerii i oferty (LightBox)*/$(function(){	$('a[rel=lightbox]').lightBox({    	overlayBgColor: '#000',    	overlayOpacity: 0.6,    	imageLoading: 'img/lightbox/loading.gif',    	imageBtnClose: 'img/lightbox/close.gif',    	imageBtnPrev: 'img/lightbox/prev.gif',    	imageBtnNext: 'img/lightbox/next.gif',    	containerResizeSpeed: 350,    	txtImage: 'praca',    	txtOf: 'z'   });});/*** Mechanizm podpowiedzi*/$(function(){    var selectors = 'a[title]:not(a[rel=lightbox]), img[title], :button[title], :submit[title]';    $(selectors).mouseover(function(event){        var tooltip = $('<div>');        tooltip.attr('id', 'tooltip');        tooltip.text($(this).attr('title'));        $(this).removeAttr('title');        $(this).attr('alt', '');        tooltip.css('top', (event.pageY + 10) + 'px');        tooltip.css('left', (event.pageX + 10) + 'px');        $('body').append(tooltip);    })    $(selectors).mousemove(function(event){        $('#tooltip').css('top', (event.pageY + 10) + 'px');        $('#tooltip').css('left', (event.pageX + 10) + 'px');    })    $(selectors).mouseout(function(){        $(this).attr('title', $('#tooltip').text());        $('#tooltip').remove();    })});/*** Mechanizm licznika znakow dla pol tekstowych formularzy*/$(function(){    var selectors = 'div.fieldset :text[maxlength], div.fieldset :password[maxlength], div.fieldset textarea[maxlength]';    $(selectors).focus(function(){        var maxlength = $(this).attr('maxlength');        var length = $(this).attr('value').length;        $('#counter').remove();        var counter = $('<span>');        counter.text(' [' + length + '/' + maxlength + ']');        counter.attr('id', 'counter');        $(this).after(counter);    })    $(selectors).keydown(function(event){        var maxlength = $(this).attr('maxlength');        var length = $(this).attr('value').length;        if ((length == maxlength) && (event.keyCode != 8) && (event.keyCode != 9) && (event.keyCode != 37) && (event.keyCode != 39))        {            return false;        }    })    $(selectors).keyup(function(){        var maxlength = $(this).attr('maxlength');        var length = $(this).attr('value').length;        $('#counter').text(' [' + length + '/' + maxlength + ']');    })    $(selectors).blur(function(){        $('#counter').remove();    })});/*** Odswiezenie obrazka CAPTCHA*/$(function(){    $('img#captcha_refresh').click(function(){        $('img#captcha').attr('src', 'captcha.php?token=' + new Date().getTime());    });});/*** Sprawdzenie dostepnosci loginu w formularzu rejestracji (AJAX)*/$(function(){    $('#is_available_button').show().click(function(){        var login = $(':input#registration_login').attr('value');        var button = $(this);        $.ajax({            type: 'POST',            url: 'ajax.php',            data: ({action: 'check_login', login: login}),            dataType: 'json',            async: true,            success: function(data){                var message = data.result ? 'Login available!' : 'Login unavailable!';                showAlert(message, 'Message');            },            error: function() {                showAlert('There is a problem. Please try again later!', 'Message');            },            beforeSend: function(){                button.before(createActionIndicator('check...'));                button.hide();            },            complete: function(){                removeActionIndicator();                button.show();            }        });    })});/*** Generowanie hasla w formularzu rejestracji (AJAX)*/$(function(){    $('#generate_password_button').show().click(function(){        var button = $(this);        $.ajax({            type: 'POST',            url: 'ajax.php',            data: ({action: 'generate_password'}),            dataType: 'json',            async: true,            success: function(data){                showAlert('Generated password: ' + data.password, 'message');                $(':password#registration_password1').attr('value', data.password);                $(':password#registration_password2').attr('value', data.password);            },            error: function() {                showAlert('There is a problem. Please try again later!', 'Message');            },            beforeSend: function(){                button.before(createActionIndicator('generate...'));                button.hide();            },            complete: function(){                removeActionIndicator();                button.show();            }        });    })});/*** Generowanie hasla w formularzu zmiany hasla (AJAX)*/$(function(){    $('#generate_new_password_button').show().click(function(){        var button = $(this);        $.ajax({            type: 'POST',            url: 'ajax.php',            data: ({action: 'generate_password'}),            dataType: 'json',            async: true,            success: function(data){                showAlert('Wygenerowane hasło: ' + data.password, 'Message');                $(':password#change_new_password1').attr('value', data.password);                $(':password#change_new_password2').attr('value', data.password);            },            error: function() {                showAlert('There is a problem. Please try again later!', 'Message');            },            beforeSend: function(){                button.before(createActionIndicator('generate...'));                button.hide();            },            complete: function(){                removeActionIndicator();                button.show();            }        });    })});/*** Domyslny tekst pola wyszukiwarki*/$(function(){    var text;    $('input#search_phrase').focus(function(){        text = $(this).attr('value');        $(this).attr('value', '');    });    $('input#search_phrase').blur(function(){        $(this).attr('value', text);    });});/*** Rejestracja - wybór typu profilu*/$(function(){    $('form#form_registration :radio[name=profile_type]').change(function(){        if (($(this).attr('value') == 'artist') || $(this).attr('value') == 'organizer')        {            $('form#form_registration tbody#artist_field').show();        }        else if ($(this).attr('value') == 'standard')        {            $('form#form_registration tbody#artist_field').hide();            $('form#form_registration tbody#location_fields').hide();            $('form#form_registration tbody#artist_field :checkbox[name=location]').removeAttr('checked');        }    })});/*** Rejestracja/edycja danych - przelaczanie widocznosci pol formularza dla danych lokalizacji*/$(function(){    $('form#form_registration :checkbox[name=location], form#form_editing :checkbox[name=location]').change(function(){        if ($(this).attr('checked'))        {            $('tbody#location_fields').show();        }        else        {            $('tbody#location_fields').hide();        }    })});/*** Mechanizm akoredonu dla tematow pomocy i polityki prywatnosci*/$(function(){    if ($('#accordion').length > 0)    {        var subject_nr = location.hash ? (parseInt(location.hash.substring(8)) - 1) : 'none';        $('#accordion').accordion({            header: 'h2',            autoHeight: false,            active: subject_nr        });        if (location.hash)        {            $(window).scrollTop($('h2#subject' + (subject_nr + 1)).offset().top);        }    }});/*** Dodawanie oferty - wybor typu*/$(function(){    $('form#form_offer_add :radio[name=type]').change(function(){        if ($(this).attr('value') == 'service')        {            $('form#form_offer_add tr:has(#offer_expires_date)').hide();            $('form#form_offer_add tr:has(select#offer_gallery)').show();        }        else if ($(this).attr('value') == 'order')        {            $('form#form_offer_add tr:has(select#offer_gallery)').hide();            $('form#form_offer_add tr:has(#offer_expires_date)').show();        }    })});/*** Dodawanie wydarzenia - przelaczanie widocznosci pol formularza dla danych lokalizacji*/$(function(){    $('form#form_event_add :checkbox[name=location]').change(function(){        if ($(this).attr('checked'))        {            $('form#form_event_add tbody#locality_fields').show();        }        else        {            $('form#form_event_add tbody#locality_fields').hide();        }    })});/*** Ocena galerii*/$(function(){    $('form#form_rating :radio').click(function(){        $(this).parents('form').submit();    })});/*** Przesuniecie suwaka przegladarki do pierwszego blednie wypelnionego pola formularza*/$(function(){    if ($('img.incorrect_icon').length > 0)    {        $(window).scrollTop($('img.incorrect_icon').eq(0).offset().top - 20);    }});/*** Wyswietlenie mapy (Google Maps API)*/$(function(){    if (($('div#gmap').length > 0) && GBrowserIsCompatible())    {        var map = new GMap2(document.getElementById('gmap'));        var point = new GLatLng(latitude, longitude);        map.setCenter(point, 13);        var marker = new GMarker(point);        map.addOverlay(marker);        map.setUIToDefault();    }});/*** Mechanizm kalendarza dla pola tekstowego*/$(function(){    $('input#offer_expires_date, input#event_date_start, input#event_date_end').datepicker($.datepicker.regional['pl']);});/*** Podmiana czcionek (Cufon)*/$(function(){    if ($.browser.msie == true)    {    	Cufon.now();    };    Cufon.replace(['ul#menulist li a', 'div#title h1', 'div.legend span']);});/*** Wskaznik akcji zamiast przycisku zatwierdzania formularzy*/$(function(){    $('div#content :submit').click(function(){        $(this).after(createActionIndicator('doing...'));        $(this).hide();    })});$(document).ready(function(){    $("<img>").attr("src", "img/loading.gif");    //preferencje    if ($.cookie("preferences") == "show")    {        $("#show").hide();        $("#hide").show();        $("#form_preferences").show();    }    else if ($.cookie("preferences") == "hide")    {        $("#show").show();        $("#hide").hide();        $("#form_preferences").hide();    }    else    {        $("#show").hide();        $("#hide").show();    }    $("#show").click(function(){        $("#show").toggle();        $("#hide").toggle();        $("#form_preferences").slideToggle();        $.cookie("preferences", "show");        return false;    })    $("#hide").click(function(){        $("#show").toggle();        $("#hide").toggle();        $("#form_preferences").slideToggle();        $.cookie("preferences", "hide");        return false;    })    confirmBeforeSubmit("form.item_remove", "Remove item from Watchlist?");    confirmBeforeSubmit("form.offer_remove", "Delete offer?");    confirmBeforeSubmit("form.gallery_remove", "Remove all the gallery and its work?");    confirmBeforeSubmit("form.work_remove", "Remove work?");    confirmBeforeSubmit("form.event_remove", "Remove event?");    confirmBeforeSubmit("form#profile_remove", "Remove all Your profile?");})//potwierdzenie usuwaniafunction confirmBeforeSubmit(selector, message){    $(selector).submit(function(){        var form = this;        showAlert(message, "Confirmation", function(){            form.submit();        })        return false;    });}//alertfunction showAlert(message, title, func){    var argc = arguments.length;    var popup = $("<div>");    popup.attr("id", "alert");    var top = (($(window).height() / 2) - 80) + $(window).scrollTop();    var left = (($(window).width() / 2) - 175);    popup.css("top", top + "px");    popup.css("left", left + "px");    var button_ok = $("<input>");    button_ok.attr("type", "button");    button_ok.attr("value", "ok");    button_ok.addClass("button100c");    if (argc == 3)    {        var button_cancel = $("<input>");        button_cancel.attr("type", "button");        button_cancel.attr("value", "cancel");        button_cancel.addClass("button100c");    }    var label = $("<div>");    label.attr("id", "label");    label.text(title);    var text = $("<div>");    text.attr("id", "text");    text.text(message);    popup.append(label);    popup.append(text);    popup.append(button_ok);    if (argc == 3)    {        popup.append(button_cancel);    }    var wall = $("<div>");    wall.attr("id", "wall");    wall.width($(document).width());    wall.height($(document).height());    $("body").append(wall);    $("body").append(popup);    button_ok.trigger("focus");    if (argc == 3)    {        button_cancel.click(function(){            popup.remove();            wall.remove();        })    }    button_ok.click(function(){        if (argc == 3)        {            func();        }        popup.remove();        wall.remove();    })}//utworzenie ikony bledufunction createIncorrectIcon(title){    var icon = $("<img>");    icon.attr("src", "img/incorrect.png");    icon.attr("width", "16");    icon.attr("height", "16");    icon.attr("alt", "[?]");    icon.attr("title", title);    icon.addClass("incorrect_icon");    return icon;}//tworzy wskaznik akcjifunction createActionIndicator(message){    var action_indicator = $("<span>");    action_indicator.attr("id", "action_indicator");    var loading = $("<img>");    loading.attr("src", "img/loading.gif");    loading.attr("width", 28);    loading.attr("height", 28);    loading.css("verticalAlign", "middle");    action_indicator.append(loading);    action_indicator.append(message);    return action_indicator;}//usuwa wskaznik akcjifunction removeActionIndicator(){    $("span#action_indicator").remove();}
