/* Funkcja zmieniająca aktualne wpisy w koszyku zakupów oraz obliczające wartość produktów -------------*/
// author: Tomasz ROGALSKI
function changeCart(action, id){
    var sum = 0;
    var promocja = false;
    $('table#cart').find('tr').remove(); //Czyszczenie okna Twoje zakupy
    switch(action){
        case 'change':
            if($('#prodAdder8_h').val() == 'on')
            {
                sum += 399;
                $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">Adder 8</td><td class="calc_net">'+(399/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">399.00zł brutto</td><td class="td_border"></td></tr>');
                promocja = true;
            }
            if($('#prodSupport_h').val() == 'on')
            {
                sum += 50;
                $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">Support</td><td class="calc_net">'+(50/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">50.00zł brutto</td><td class="td_border"></td></tr>');
                promocja = true;
            }

            if($('#prodUpdate_h').val() == 'on'){
                var update_price = $('#updateFrom_h').val();
                switch(update_price){
                    case '3':
                        sum += 179;
                         $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">Aktualizacja Adder 3 - 8</td><td class="calc_net">'+(179/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">179.00zł brutto</td><td class="td_border"></td></tr>');
                        break;
                    case '4':
                        sum += 159;
                         $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">Aktualizacja Adder 4 - 8</td><td class="calc_net">'+(159/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">159.00zł brutto</td><td class="td_border"></td></tr>');
                        break;
                    case '5':
                        sum += 139;
                        $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">Aktualizacja Adder 5 - 8</td><td class="calc_net">'+(139/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">139.00zł brutto</td><td class="td_border"></td></tr>');
                        break;
                    case '6':
                        sum += 119;
                        $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">Aktualizacja Adder 6 - 8</td><td class="calc_net">'+(119/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">119.00zł brutto</td><td class="td_border"></td></tr>');
                        break;
					case '7':
                        sum += 98;
                        $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">Aktualizacja Adder 7 - 8</td><td class="calc_net">'+(98/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">98.00zł brutto</td><td class="td_border"></td></tr>');
                        break;	
                }
		promocja = true;
            }

			if($('#prodAnal').attr('checked')==true)
          //  if($('#prodAnal_h').val() == 'on')
            {
                sum += 99;
                $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">Analiza WWW</td><td class="calc_net">'+(99/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">99.00zł brutto</td><td class="td_border"></td></tr>');
            }

			if($('#prodCleaner').attr('checked')==true)
          //  if($('#prodCleaner_h').val() == 'on')
            {
                sum += 35;
                 $('#cart').append('<tr><td class="td_border"></td><td class="calc_name">CodeCleaner</td><td class="calc_net">'+(35/1.23).toFixed(2)+'zł netto</td><td class="calc_gross">35.00zł brutto</td><td class="td_border"></td></tr>');
            }

            var sum_netto = sum / 1.23; //Należy poprawnie obliczyć wartość netto.
            var buf = sum_netto * 100;
            buf = Math.round(buf);
            sum_netto = (buf / 100).toFixed(2);
            sum = sum.toFixed(2);
            $('#cart').append('<tr class="calc_ex"><th class="td_border"></th><th class="calc_name">Razem</th><th class="calc_net" id="sum_net">'+sum_netto+'zł netto</th><th class="calc_gross" id="sum_gross">'+sum+'zł brutto</th><th class="td_border"></th></tr>');
            break;
        case 'add':
            if(id == 'prodUpdate'){
                $('#'+id+'_h').val('on');
            }
            else $('#'+id+'_h').val('on');
            break;
        case 'remowe':
            $('#'+id+'_h').val('off');
            break;
    }
}



/* Fukcja zmieniająca cenne w zaleznosci od wersji z ktorej sie aktualizuje -------------*/
// author: Tomasz ROGALSKI
function changeUpdate(){
    var price = $('#updateFrom').val();
    switch(price){
		case '7':
            $('#update_price').html('98zł');
            $('#updateFrom_h').val(price);
            break;
        case '6':
            $('#update_price').html('119zł');
            $('#updateFrom_h').val(price);
            break;
        case '5':
            $('#update_price').html('139zł');
            $('#updateFrom_h').val(price);
            break;
        case '4':
            $('#update_price').html('159zł');
            $('#updateFrom_h').val(price);
            break;
        case '3':
            $('#update_price').html('179zł');
            $('#updateFrom_h').val(price);
            break;
    }
    changeCart('change');
}


/* Fukcja zmieniająca cenne w zaleznosci od ilości artykułów -------------*/
function changeileArt(){
    var price = $('#ileArt').val();
    $('#art_price').html(price+ ' zł');
    switch(price){
        case '1':
            $('#art_price').html('99 zł');
            $('#ileArt_h').val(price);
            break;
        case '2':
            $('#art_price').html('189 zł');
            $('#ileArt_h').val(price);
            break;
        case '3':
            $('#art_price').html('297 zł');
            $('#ileArt_h').val(price);
            break;
        case '4':
            $('#art_price').html('396 zł');
            $('#ileArt_h').val(price);
            break
        case '5':
            $('#art_price').html('495 zł');
            $('#ileArt_h').val(price);
            break
    }
    changeCartPrecle('change');
}


/* Funkcja zmieniająca aktualne wpisy w koszyku zakupów oraz obliczające wartość produktów -------------*/
// author: Tomasz ROGALSKI
function changeCartPrecle(action, id){
    var sumP = 0;
    $('#cartPrecle').html(''); //Czyszczenie okna Twoje zakupy
    switch(action){
        case 'change':
			if($('#prodPrecl_h').attr('checked')==true)
            //if($('#prodPrecl_h').val() == 'on')
			{
                var art_price = $('#ileArt_h').val();
                switch(art_price){
                    case '1':
                        sumP += 99;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Artykuł</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>99.00 zł</b></li>');
                        break;
                    case '2':
                        sumP += 198;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Artykuł</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>189.00 zł</b></li>');
                        break;
                    case '3':
                        sumP += 297;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Artykuł</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>297.00 zł</b></li>');
                        break;
                    case '4':
                        sumP += 396;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Artykuł</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>396.00 zł</b></li>');
                        break;
                    case '5':
                        sumP += 495;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Artykuł</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>495.00 zł</b></li>');
                        break;
                }
            }
			if($('#prodKonfStr_h').attr('checked')==true)
            //if($('#prodKonfStr_h').val() == 'on')
			{
                var konf_price = $('#ileKonf_h').val();
                switch(konf_price){
                    case '1':
                        sumP += 169;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Konfiguracja</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>169.00 zł</b></li>');
                        break;
                    case '2':
                        sumP += 338;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Konfiguracja</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>338.00 zł</b></li>');
                        break;
                    case '3':
                        sumP += 507;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Konfiguracja</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>507.00 zł</b></li>');
                        break;
                    case '4':
                        sumP += 676;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Konfiguracja</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>676.00 zł</b></li>');
                        break;
                    case '5':
                        sumP += 845;
                        $('#cartPrecle').append('<li class="cartPrecle_desc text_11">Konfiguracja</li>');
                        $('#cartPrecle').append('<li class="cartPrecle_price"><b>845.00 zł</b></li>');
                        break;
                }
            }

            var sumP_netto = sumP / 1.23; //Należy poprawnie obliczyć wartość netto.
            $('#cartPrecle_sum').html(''); //czyszczenie sumy Twoje zakupy
            $('#cartPrecle_sum').html('<b>'+sumP+'.00 zł</b><br />');
            var buf = sumP_netto * 100;
            buf = Math.round(buf);
            sumP_netto = buf / 100;
            $('#cartPrecle_sum').append('<span class="text_11">(netto: '+sumP_netto+' zł)</span>');
            $('#cartPrecle').append('<li style="clear:both">&nbsp;</li>'); //Dodanie odstępu po ostatnich zakupach (wlasność tylko graficzna)
            break;
        case 'add':
            if(id == 'prodPrecl' || id == 'prodKonfSt'){
                $('#'+id+'_h').val('on');
            }
            else $('#'+id+'_h').val('on');
            break;
        case 'remowe':
            $('#'+id+'_h').val('off');
            break;
    }

}

function changeileKonf(){
    var price = $('#ileKonf').val();
    $('#konf_price').html(price+ ' zł');
    switch(price){
        case '1':
            $('#art_price').html('169 zł');
            $('#ileKonf_h').val(price);
            break;
        case '2':
            $('#art_price').html('338 zł');
            $('#ileKonf_h').val(price);
            break;
        case '3':
            $('#art_price').html('507 zł');
            $('#ileKonf_h').val(price);
            break;
        case '4':
            $('#art_price').html('676 zł');
            $('#ileKonf_h').val(price);
            break
        case '5':
            $('#art_price').html('845 zł');
            $('#ileKonf_h').val(price);
            break
    }
    changeCartPrecle('change');

}

// Rozsuniecie lub zsuniecie boxa produktu w kup teraz oraz wywolanie aktualizacji koszyka
function changeChbox(id, changeStatus)
{
    if(changeStatus == true)
    {
        $('#'+id).attr('checked', !$('#'+id).attr('checked'));
    }

    if($('#'+id).attr('checked') == true)
    {
        $('#'+id+'Info').slideDown();
        changeCart('add', id);
    }
    else
    {
        $('#'+id+'Info').slideUp();
        changeCart('remowe', id)
    }
    changeCart('change'); //Uruchomienie funkcji zmieniającej wpisy w kwadracie Twoje zakupy
    changeCartPrecle('change');
}
//$('#wwwAnal').click(function(){
//   $('#analBox').slideDown();
//});

function copyVatData(){
    document.getElementById('vatname').value = document.getElementById('name').value;
    document.getElementById('vatcity').value = document.getElementById('city').value;
    document.getElementById('vataddress').value = document.getElementById('address').value;
    document.getElementById('vatpostal').value = document.getElementById('postal').value;
}

//kopiowanie danych do faktury przy zakupie artykułów
function copyVatPrecle(){
    document.getElementById('vatnamePrecl').value = document.getElementById('name').value;
    document.getElementById('vatcityPrecl').value = document.getElementById('city').value;
    document.getElementById('vataddressPrecl').value = document.getElementById('address').value;
    document.getElementById('vatpostalPrecl').value = document.getElementById('postal').value;
}

// Funkcja wysyłająca formularz o określonym id
// author: Tomasz ROGALSKI
function submitForm(id){
    $("#"+id).submit();
}

// Funkcja sprawdzająca poprawność wpisanych danych w formularzu potwierdzajacym zakup
// author: Tomasz ROGALSKI
function validFormSellConfirm(name, domen_instal, email, faktura){
    name = $('#'+name).val();
    var city = $('#city').val();
    domen_instal = $('#'+domen_instal).val();
    var address = $('#address').val();
	var tel = $('#tel').val();
    email = $('#'+email).val();
    faktura = $('#'+faktura).attr('checked');
    var vatname = $('#vatname').val();
    var vatcity = $('#vatcity').val();
    var vatnip = $('#vatnip').val();
    var vataddress = $('#vataddress').val();
    var vatpostal = $('#vatpostal').val();
    var wwwanal = $('#wwwanal').val();
    var reg = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/; //preg walidujacy e-mail
    email = reg.test(email);

    if(faktura){
        if($('#wwwanalcheck').attr('checked') || $('#prodAnal_h').val() == 'on'){
            if(name && domen_instal && email && city && address && wwwanal && vatname && vatcity && vatnip && vataddress && vatpostal && tel){
                reg = /^(localhost).*$/
                var test = reg.test(domen_instal)
                if(test){
                    alert('Domena nie może być localhost');
                    return false;
                }
                else return true;
            }
            else{
                alert('Proszę wypełnić poprawnie wszystkie pola');
                return false;
            }
        }
        else{
            if(name && domen_instal && email && city && address && vatname && vatcity && vatnip && vataddress && vatpostal && tel){
                reg = /^(localhost).*$/
                test = reg.test(domen_instal)
                if(test){
                    alert('Domena nie może być localhost');
                    return false;
                }
                else return true;
            }
            else{
                alert('Proszę wypełnić poprawnie wszystkie pola');
                return false;
            }
        }
    }
    else{
        if($('#wwwanalcheck').attr('checked') || $('#prodAnal_h').val() == 'on'){
            if(name && domen_instal && email && city && address && wwwanal && tel){
                reg = /^.*(localhost).*$/
                test = reg.test(domen_instal)
                if(test){
                    alert('Domena nie może być localhost');
                    return false;
                }
                else return true;
            }
            else{
                alert('Proszę wypełnić poprawnie wszystkie pola');
                return false;
            }
        }
        else{
            if(name && domen_instal && email && city && address && tel){
                reg = /^.*(localhost).*$/
                test = reg.test(domen_instal)
                if(test){
                    alert('Domena nie może być localhost');
                    return false;
                }
                else return true;
            }
            else{
                alert('Proszę wypełnić poprawnie wszystkie pola');
                return false;
            }
        }

    }

}

function validFormArtConfirm(){
    var err = 0;
    var email;
    var vatnip;
    var reg;
    var reg1;
    var msgError = '';
    $(":input[type=text]").each(function(){
        var nazwa = $(this).attr("name");
        if(nazwa != 'email' && nazwa != 'q' && nazwa != 'fakturaPrecl' && nazwa != 'vatnamePrecl' && nazwa != 'vataddressPrecl' && nazwa != 'vatnipPrecl' && nazwa != 'vatcityPrecl' && nazwa != 'vatpostalPrecl')
        {
            var pole = $(this).val();
            if(pole == '')
            {
                err++;
                msgError = 'Proszę uzupełnić poprawnie wszystkie pola. ';
            }
        }
        else if( nazwa == 'email' )
        {
            reg = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/; //preg walidujacy e-mail
            email = reg.test($('#email').val());
            if(!email)
            {
                err++;
                msgError += 'Niepoprawny adres email. ';
            }
        }
    });
    if($('#fakturaPrecl').attr('checked'))
    {
        var vatName = $('#vatnamePrecl').val();
        var vatAddress = $('#vataddressPrecl').val();
        var vatNIP = $('#vatnipPrecl').val();
        var vatCity = $('#vatcityPrecl').val();
        var vatPostal = $('#vatpostalPrecl').val();
        if(!vatName || !vatAddress || !vatNIP || !vatCity || !vatPostal)
        {
            err++;
            msgError = 'Proszę uzupełnić poprawnie wszystkie pola. ';
        }
        reg1 = /^[0-9]{10}/;
        vatnip = reg1.test($('#vatnipPrecl').val());
        if(!vatnip)
        {
            err++;
            msgError += 'Niepoprawny format numeru NIP. ';
        }
    }
    if(err)
    {
        alert(msgError);
        return false
    }
    else return true;
}

/* Fukcja tworząca liste tematów zapytań w zależności od wyboru kategorii -------------*/
// author: Tomasz ROGALSKI
function makeList(id1, id2){ /*(id1 - obiekt select z ktorego pobierana jest categorai do tworzenia listy); (id2 - obiekt select w którym będzie robiona lista) */
    var category = $('#' + id1).val();
    $('#' + id2).html('');
    var i = 1;
    var adres = './lib/pomoc.php?category='+category+'&jsoncallback=?'
    $.getJSON(adres, function(data){
        $('#' + id2).html('');
        $.each(data, function() {
            var tematy = '<option value="'+i+'">'+data[i]+'</option>';
            $('#' + id2).append(tematy);
            i++;
        });
    });
}
/* Fukcja tworząca adres w action w formularzu pomocy w zależności od wyboru kategorii i tematu dlatego ze jest codecleaner -------------*/
// author: Tomasz ROGALSKI
function makeAdres(id1, id2){
    var category = $('#' + id1).val();
    var temat = $('#' + id2).val();
    if(category == 6 && temat == 1) $('#pomocForm').attr('action', 'program-partnerski.html');
    else if(category == 6 && temat == 2) $('#pomocForm').attr('action', 'kontakt.html');
    else if(category == 7 && (temat == 1 || temat == 2 || temat == 3)) $('#pomocForm').attr('action', 'kontakt.html');
    else if(category == 3){
        if(temat == 1) $('#pomocForm').attr('action', 'regulamin-bok.html#mail');
        else if(temat == 2) $('#pomocForm').attr('action', 'regulamin-bok.html#support');
        else if(temat == 3) $('#pomocForm').attr('action', 'regulamin-bok.html#naprawa');
        else if(temat == 4) $('#pomocForm').attr('action', 'regulamin-bok.html#reklamacje');
        else if(temat == 5) $('#pomocForm').attr('action', 'regulamin-bok.html#faktury');
        else if(temat == 6) $('#pomocForm').attr('action', 'regulamin-bok.html#bezpieczenstwo');
    }
    else $('#pomocForm').attr('action', 'pomoc-'+category+'-'+temat+'.html'); //dynamiczna zmiana adresu action w formularzu
}

$().ready(function(){

   // przełączanie kart na kup teraz
$('div.framed_tab li a').click(function(){
    $("div.framed_tab ul input[@type=checkbox]").each(
    function() {
       $(this).removeAttr('checked');
    }
);
 $('div.framed_tab ul').find('a').removeClass('current');
 $('div.tab_content').hide();
 $(this).addClass('current');
 $(this).find('input[@type=checkbox]').attr('checked','checked');
 $('div#'+$(this).attr('id')+'_txt').show();
});

$('ul.nb').find('li:last').css({'background':'none','padding-right':'0'});


// select kup teraz
$('#updateFrom').change(function() {
$('#updateFrom_txt').text('Adder '+$(this).val());
});
// precle
$('#p1_next').click(function(){
   $('#formKrok1').submit();
});
$('#p2_next').click(function(){
   $('#formKrok2').submit();
});
$('#p3_next').click(function(){
   $('#formKrok3').submit();
});
$('#p4_next').click(function(){
   $('#formp').submit();
});

$('#s2_next').click(function(){
   $('#formStep2').submit();
});
$('#s4_next').click(function(){
   $('#formStep4').submit();
});
$('#s5_next').click(function(){
   $('#formp').submit();
});


    // Rozsuwane boxy w kup teraz
    $('#prodAdder8').click(function(){
        changeChbox($(this).attr('id'), false);
    });
    $('#prodAdder8Box').click(function(){
        changeChbox('prodAdder8', true);
    });

    $('#prodSupport').click(function(){
        changeChbox($(this).attr('id'), false);
    });
    $('#prodSupportBox').click(function(){
        changeChbox('prodSupport', true);
    });

    $('#prodUpdate').click(function(){
        changeChbox($(this).attr('id'), false);
    });
    $('#prodUpdateBox').click(function(){
        changeChbox('prodUpdate', true);
    });

    $('#prodAnal').click(function(){
        changeChbox($(this).attr('id'), true);
    });
    $('#prodAnalBox').click(function(){
        changeChbox('prodAnal', true);
    });

    $('#prodCleaner').click(function(){
        changeChbox($(this).attr('id'), true);
    });
    $('#prodCleanerBox').click(function(){
        changeChbox('prodCleaner', true);
    });

    $('#wwwanalcheck').click(function(){
        changeChbox($(this).attr('id'), false);
    });
    $('#wwwanalcheckBox').click(function(){
        changeChbox('wwwanalcheck', true);
    }); /* Krok 3 pokazywanie bloku do wpisania adresu  */

	
	$('#calcheck').click(function(){
        changeChbox($(this).attr('id'), false);
		if($('#calcheck').attr('checked')==false)
			$('#domain').val('cal24.pl');
		else
			$('#domain').val('');
    });
	$('#calcheckBox').click(function(){
        changeChbox('calcheck', true);
		if($('#calcheck').attr('checked')==false)
			$('#domain').val('cal24.pl');
		else
			$('#domain').val('');
    }); /* Krok 3 pokazywanie bloku do wpisania adresu  */
	
	
    $('#faktura').click(function(){
        changeChbox($(this).attr('id'), false);
    });
    $('#fakturaBox').click(function(){
        changeChbox('faktura', true);
    });

    //Rozsuwane boxy w preclach
    $('#prodPrecl').click(function(){
        changeChbox($(this).attr('id'), true);
    });
    $('#prodPreclBox').click(function(){
        changeChbox('prodPrecl', true);
    });

    $('#prodKonfStr').click(function(){
        changeChbox($(this).attr('id'), true);
    });
    $('#prodKonfStrBox').click(function(){
        changeChbox('prodKonfStr', true);
    });

    $('#fakturaPrecl').click(function(){
        changeChbox($(this).attr('id'), false);
    });
    $('#fakturaPreclBox').click(function(){
        changeChbox('fakturaPrecl', true);
    })

    // Rozsuwane boxy w kup teraz KONIEC!!

    $('#updateFrom').change(function(){
        changeUpdate()
    }); /* --- Zmiana ceny w aktualizacji addera --- */  
   changeUpdate(); /* --- Zmiana ceny w aktualizacji addera po zaladowaniu strony--- */



    $('#Select1').change(function(){
        makeList('Select1', 'Select2')
    }); /* --- Tworzenie listy tematów w zależności od wyboru kategorii --- */
    $('#Select2').change(function(){
        makeAdres('Select1', 'Select2')
    }); /* --- Tworzenie listy tematów w zależności od wyboru kategorii --- */

    $('li[id^="question_"]').click(function(){
        develope_hide($(this).attr('id'))
    }); /* --- Rozwijanie pomocy --- */

    $('li[id^="news_"]').click(function(){
        develope_hide_news($(this).attr('id'))
    }); /* --- Rozwijanie news'a --- */

    $('#pomocForm').submit(function(){
        return validform('Select1', 'Select2')
    });

    $('#formularzKontakt').submit(function(){
        return validFormContact('name', 'email', 'msg')
    }); //Waliacja formularza kontatkowego

    $('#formStep3').submit(function(){
            return validFormSellConfirm('name', 'domain', 'email', 'faktura');
        }); //Waliacja formularza zakupu
    
    $('#formKrok2').submit(function(){
        return validFormArtConfirm();
    }); //Waliacja formularza zakupu artykułu

    $('#ileArt').change(function(){
        changeileArt();
    }); /* --- Zmiana ceny w zależności od ilości artykułów  --- */
    changeileArt(); /* --- Zmiana ceny w zależności od ilości artykułów po zaladowaniu strony--- */

    $('#ileKonf').change(function(){
        changeileKonf();
    }); /* --- Zmiana ceny w zależności od ilości konfiguracji  --- */
    changeileKonf(); /* --- Zmiana ceny w zależności od ilości konfiguracji po zaladowaniu strony--- */

    //Zatwierdzenie formularzy w kup teraz poprzez js
    $('#krok2').click(function(e){
        e.preventDefault();
        submitForm('formStep1');
    });
    $('#krok3').click(function(e){
        e.preventDefault();
        submitForm('formStep2');
    });
    $('#krok4,#s3_next').click(function(e){
        e.preventDefault();
        submitForm('formStep3');
    });
    $('#krok5').click(function(e){
        e.preventDefault();
        submitForm('formStep4');
    });
    //Zatwierdzenie formularzy w kup teraz poprzez js - KONIEC

    //Zatwierdzenie formularzy w precle poprzez js
    $('#precle2').click(function(e){
        e.preventDefault();
        submitForm('formKrok1');
    });
    $('#precle3').click(function(e){
        e.preventDefault();
        submitForm('formKrok2');
    });
    $('#precle4').click(function(e){
        e.preventDefault();
        submitForm('formKrok3');
    });

	changeCart('change'); //Uruchomienie funkcji zmieniającej wpisy w kwadracie Twoje zakupy

//Zatwierdzenie formularzy w precle poprzez js - KONIEC
})

$('#buttonNextX').click(function(){
    var r = false;
    $('input[id!=prod]').each(function(){
        if($(this).checked == true)
        {
            r = true;
        }
    })
    if(r === false)
    {
        alert('Żaden produkt nie został zaznaczony...');
    }
})


















/**
 * SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof deconcept=="undefined"){var deconcept=new Object();}if(typeof deconcept.util=="undefined"){deconcept.util=new Object();}if(typeof deconcept.SWFObjectUtil=="undefined"){deconcept.SWFObjectUtil=new Object();}deconcept.SWFObject=function(_1,id,w,h,_5,c,_7,_8,_9,_a){if(!document.getElementById){return;}this.DETECT_KEY=_a?_a:"detectflash";this.skipDetect=deconcept.util.getRequestParameter(this.DETECT_KEY);this.params=new Object();this.variables=new Object();this.attributes=new Array();if(_1){this.setAttribute("swf",_1);}if(id){this.setAttribute("id",id);}if(w){this.setAttribute("width",w);}if(h){this.setAttribute("height",h);}if(_5){this.setAttribute("version",new deconcept.PlayerVersion(_5.toString().split(".")));}this.installedVer=deconcept.SWFObjectUtil.getPlayerVersion();if(!window.opera&&document.all&&this.installedVer.major>7){deconcept.SWFObject.doPrepUnload=true;}if(c){this.addParam("bgcolor",c);}var q=_7?_7:"high";this.addParam("quality",q);this.setAttribute("useExpressInstall",false);this.setAttribute("doExpressInstall",false);var _c=(_8)?_8:window.location;this.setAttribute("xiRedirectUrl",_c);this.setAttribute("redirectUrl","");if(_9){this.setAttribute("redirectUrl",_9);}};deconcept.SWFObject.prototype={useExpressInstall:function(_d){this.xiSWFPath=!_d?"expressinstall.swf":_d;this.setAttribute("useExpressInstall",true);},setAttribute:function(_e,_f){this.attributes[_e]=_f;},getAttribute:function(_10){return this.attributes[_10];},addParam:function(_11,_12){this.params[_11]=_12;},getParams:function(){return this.params;},addVariable:function(_13,_14){this.variables[_13]=_14;},getVariable:function(_15){return this.variables[_15];},getVariables:function(){return this.variables;},getVariablePairs:function(){var _16=new Array();var key;var _18=this.getVariables();for(key in _18){_16[_16.length]=key+"="+_18[key];}return _16;},getSWFHTML:function(){var _19="";if(navigator.plugins&&navigator.mimeTypes&&navigator.mimeTypes.length){if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","PlugIn");this.setAttribute("swf",this.xiSWFPath);}_19="<embed type=\"application/x-shockwave-flash\" src=\""+this.getAttribute("swf")+"\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\"";_19+=" id=\""+this.getAttribute("id")+"\" name=\""+this.getAttribute("id")+"\" ";var _1a=this.getParams();for(var key in _1a){_19+=[key]+"=\""+_1a[key]+"\" ";}var _1c=this.getVariablePairs().join("&");if(_1c.length>0){_19+="flashvars=\""+_1c+"\"";}_19+="/>";}else{if(this.getAttribute("doExpressInstall")){this.addVariable("MMplayerType","ActiveX");this.setAttribute("swf",this.xiSWFPath);}_19="<object id=\""+this.getAttribute("id")+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\""+this.getAttribute("width")+"\" height=\""+this.getAttribute("height")+"\" style=\""+this.getAttribute("style")+"\">";_19+="<param name=\"movie\" value=\""+this.getAttribute("swf")+"\" />";var _1d=this.getParams();for(var key in _1d){_19+="<param name=\""+key+"\" value=\""+_1d[key]+"\" />";}var _1f=this.getVariablePairs().join("&");if(_1f.length>0){_19+="<param name=\"flashvars\" value=\""+_1f+"\" />";}_19+="</object>";}return _19;},write:function(_20){if(this.getAttribute("useExpressInstall")){var _21=new deconcept.PlayerVersion([6,0,65]);if(this.installedVer.versionIsValid(_21)&&!this.installedVer.versionIsValid(this.getAttribute("version"))){this.setAttribute("doExpressInstall",true);this.addVariable("MMredirectURL",escape(this.getAttribute("xiRedirectUrl")));document.title=document.title.slice(0,47)+" - Flash Player Installation";this.addVariable("MMdoctitle",document.title);}}if(this.skipDetect||this.getAttribute("doExpressInstall")||this.installedVer.versionIsValid(this.getAttribute("version"))){var n=(typeof _20=="string")?document.getElementById(_20):_20;n.innerHTML=this.getSWFHTML();return true;}else{if(this.getAttribute("redirectUrl")!=""){document.location.replace(this.getAttribute("redirectUrl"));}}return false;}};deconcept.SWFObjectUtil.getPlayerVersion=function(){var _23=new deconcept.PlayerVersion([0,0,0]);if(navigator.plugins&&navigator.mimeTypes.length){var x=navigator.plugins["Shockwave Flash"];if(x&&x.description){_23=new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/,"").replace(/(\s+r|\s+b[0-9]+)/,".").split("."));}}else{if(navigator.userAgent&&navigator.userAgent.indexOf("Windows CE")>=0){var axo=1;var _26=3;while(axo){try{_26++;axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+_26);_23=new deconcept.PlayerVersion([_26,0,0]);}catch(e){axo=null;}}}else{try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");}catch(e){try{var axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");_23=new deconcept.PlayerVersion([6,0,21]);axo.AllowScriptAccess="always";}catch(e){if(_23.major==6){return _23;}}try{axo=new ActiveXObject("ShockwaveFlash.ShockwaveFlash");}catch(e){}}if(axo!=null){_23=new deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));}}}return _23;};deconcept.PlayerVersion=function(_29){this.major=_29[0]!=null?parseInt(_29[0]):0;this.minor=_29[1]!=null?parseInt(_29[1]):0;this.rev=_29[2]!=null?parseInt(_29[2]):0;};deconcept.PlayerVersion.prototype.versionIsValid=function(fv){if(this.major<fv.major){return false;}if(this.major>fv.major){return true;}if(this.minor<fv.minor){return false;}if(this.minor>fv.minor){return true;}if(this.rev<fv.rev){return false;}return true;};deconcept.util={getRequestParameter:function(_2b){var q=document.location.search||document.location.hash;if(_2b==null){return q;}if(q){var _2d=q.substring(1).split("&");for(var i=0;i<_2d.length;i++){if(_2d[i].substring(0,_2d[i].indexOf("="))==_2b){return _2d[i].substring((_2d[i].indexOf("=")+1));}}}return "";}};deconcept.SWFObjectUtil.cleanupSWFs=function(){var _2f=document.getElementsByTagName("OBJECT");for(var i=_2f.length-1;i>=0;i--){_2f[i].style.display="none";for(var x in _2f[i]){if(typeof _2f[i][x]=="function"){_2f[i][x]=function(){};}}}};if(deconcept.SWFObject.doPrepUnload){if(!deconcept.unloadSet){deconcept.SWFObjectUtil.prepUnload=function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){};window.attachEvent("onunload",deconcept.SWFObjectUtil.cleanupSWFs);};window.attachEvent("onbeforeunload",deconcept.SWFObjectUtil.prepUnload);deconcept.unloadSet=true;}}if(!document.getElementById&&document.all){document.getElementById=function(id){return document.all[id];};}var getQueryParamValue=deconcept.util.getRequestParameter;var FlashObject=deconcept.SWFObject;var SWFObject=deconcept.SWFObject;

























/* ------------------------------------------------------------------------
	Class: prettyPhoto
	Use: Lightbox clone for jQuery
	Author: Stephane Caron (http://www.no-margin-for-errors.com)
	Version: 2.4.3
------------------------------------------------------------------------- */

var $pp_pic_holder;
var $ppt;

(function($) {
	$.fn.prettyPhoto = function(settings) {
		// global Variables
		var doresize = true;
		var percentBased = false;
		var imagesArray = [];
		var setPosition = 0; /* Position in the set */
		var pp_contentHeight;
		var pp_contentWidth;
		var pp_containerHeight;
		var pp_containerWidth;
		var pp_type = 'image';
	
		// Global elements
		var $caller;
		var $scrollPos = _getScroll();
	
		$(window).scroll(function(){ $scrollPos = _getScroll(); _centerPicture(); });
		$(window).resize(function(){ _centerPicture(); _resizeOverlay(); });
		$(document).keypress(function(e){
			switch(e.keyCode){
				case 37:
					if (setPosition == 1) return;
					changePicture('previous');
					break;
				case 39:
					if (setPosition == setCount) return;
					changePicture('next');
					break;
				case 27:
					close();
					break;
			};
	    });
 
	
		settings = jQuery.extend({
			animationSpeed: 'normal', /* fast/slow/normal */
			padding: 40, /* padding for each side of the picture */
			opacity: 0.80, /* Value between 0 and 1 */
			showTitle: true, /* true/false */
			allowresize: true, /* true/false */
			counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
			theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
			callback: function(){}
		}, settings);
		
		// Fallback to a supported theme for IE6
		if($.browser.msie && $.browser.version == 6){
			settings.theme = "light_square";
		}
	
		$(this).each(function(){
			var hasTitle = false;
			var isSet = false;
			var setCount = 0; /* Total images in the set */
			var arrayPosition = 0; /* Total position in the array */
			
			imagesArray[imagesArray.length] = this;
			$(this).bind('click',function(){
				open(this);
				return false;
			});
		});
	
		function open(el) {
			$caller = $(el);
		
			// Find out if the picture is part of a set
			theRel = $caller.attr('rel');
			galleryRegExp = /\[(?:.*)\]/;
			theGallery = galleryRegExp.exec(theRel);
		
			// Calculate the number of items in the set, and the position of the clicked picture.
			isSet = false;
			setCount = 0;
			
			_getFileType();
			
			for (i = 0; i < imagesArray.length; i++){
				if($(imagesArray[i]).attr('rel').indexOf(theGallery) != -1){
					setCount++;
					if(setCount > 1) isSet = true;

					if($(imagesArray[i]).attr('href') == $caller.attr('href')){
						setPosition = setCount;
						arrayPosition = i;
					};
				};
			};
		
			_buildOverlay();

			// Display the current position
			$pp_pic_holder.find('p.currentTextHolder').text(setPosition + settings.counter_separator_label + setCount);

			// Position the picture in the center of the viewing area
			_centerPicture();
		
			$('#pp_full_res').hide();
			$pp_pic_holder.find('.pp_loaderIcon').show();
		};
	
		showimage = function(width,height,containerWidth,containerHeight,contentHeight,contentWidth,resized){
			$('.pp_loaderIcon').hide();

			if($.browser.opera) {
				windowHeight = window.innerHeight;
				windowWidth = window.innerWidth;
			}else{
				windowHeight = $(window).height();
				windowWidth = $(window).width();
			};

			$pp_pic_holder.find('.pp_content').animate({'height':contentHeight},settings.animationSpeed);

			projectedTop = $scrollPos['scrollTop'] + ((windowHeight/2) - (containerHeight/2));
			if(projectedTop < 0) projectedTop = 0 + $pp_pic_holder.find('.ppt').height();

			// Resize the holder
			$pp_pic_holder.animate({
				'top': projectedTop,
				'left': ((windowWidth/2) - (containerWidth/2)),
				'width': containerWidth
			},settings.animationSpeed,function(){
				$pp_pic_holder.width(containerWidth);
				$pp_pic_holder.find('.pp_hoverContainer,#fullResImage').height(height).width(width);

				// Fade the new image
				$pp_pic_holder.find('#pp_full_res').fadeIn(settings.animationSpeed,function(){
					$(this).find('object,embed').css('visibility','visible');
				});

				// Show the nav elements
				_showContent();
			
				// Fade the resizing link if the image is resized
				if(resized) $('a.pp_expand,a.pp_contract').fadeIn(settings.animationSpeed);
			});
		};
		
		function _showContent(){
			// Show the nav
			if(isSet && pp_type=="image") { $pp_pic_holder.find('.pp_hoverContainer').fadeIn(settings.animationSpeed); }else{ $pp_pic_holder.find('.pp_hoverContainer').hide(); }
			$pp_pic_holder.find('.pp_details').fadeIn(settings.animationSpeed);
			
			// Show the title
			if(settings.showTitle && hasTitle){
				$ppt.css({
					'top' : $pp_pic_holder.offset().top - 22,
					'left' : $pp_pic_holder.offset().left + (settings.padding/2),
					'display' : 'none'
				});
			
				$ppt.fadeIn(settings.animationSpeed);
			};
		}
		
		function _hideContent(){
			// Fade out the current picture
			$pp_pic_holder.find('.pp_hoverContainer,.pp_details').fadeOut(settings.animationSpeed);
			$pp_pic_holder.find('#pp_full_res object,#pp_full_res embed').css('visibility','hidden');
			$pp_pic_holder.find('#pp_full_res').fadeOut(settings.animationSpeed,function(){
				$('.pp_loaderIcon').show();
			
				// Preload the image
				_preload();
			});
			
			// Hide the title
			$ppt.fadeOut(settings.animationSpeed);
		}
	
		function changePicture(direction){
			if(direction == 'previous') {
				arrayPosition--;
				setPosition--;
			}else{
				arrayPosition++;
				setPosition++;
			};

			// Allow the resizing of the images
			if(!doresize) doresize = true;

			_hideContent();
			$('a.pp_expand,a.pp_contract').fadeOut(settings.animationSpeed,function(){
				$(this).removeClass('pp_contract').addClass('pp_expand');
			});
		};
	
		function close(){
			$pp_pic_holder.find('object,embed').css('visibility','hidden');
			
			$('div.pp_pic_holder,div.ppt').fadeOut(settings.animationSpeed);
			
			$('div.pp_overlay').fadeOut(settings.animationSpeed, function(){
				$('div.pp_overlay,div.pp_pic_holder,div.ppt').remove();
			
				// To fix the bug with IE select boxes
				if($.browser.msie && $.browser.version == 6){
					$('select').css('visibility','visible');
				};
				
				settings.callback();
			});
			
			doresize = true;
		};
	
		function _checkPosition(){
			// If at the end, hide the next link
			if(setPosition == setCount) {
				$pp_pic_holder.find('a.pp_next').css('visibility','hidden');
				$pp_pic_holder.find('a.pp_arrow_next').addClass('disabled').unbind('click');
			}else{ 
				$pp_pic_holder.find('a.pp_next').css('visibility','visible');
				$pp_pic_holder.find('a.pp_arrow_next.disabled').removeClass('disabled').bind('click',function(){
					changePicture('next');
					return false;
				});
			};
		
			// If at the beginning, hide the previous link
			if(setPosition == 1) {
				$pp_pic_holder.find('a.pp_previous').css('visibility','hidden');
				$pp_pic_holder.find('a.pp_arrow_previous').addClass('disabled').unbind('click');
			}else{
				$pp_pic_holder.find('a.pp_previous').css('visibility','visible');
				$pp_pic_holder.find('a.pp_arrow_previous.disabled').removeClass('disabled').bind('click',function(){
					changePicture('previous');
					return false;
				});
			};
		
			// Change the current picture text
			$pp_pic_holder.find('p.currentTextHolder').text(setPosition + settings.counter_separator_label + setCount);
		
			$caller = (isSet) ? $(imagesArray[arrayPosition]) : $caller;
			_getFileType();

			if($caller.attr('title')){
				$pp_pic_holder.find('.pp_description').show().html(unescape($caller.attr('title')));
			}else{
				$pp_pic_holder.find('.pp_description').hide().text('');
			};
		
			if($caller.find('img').attr('alt') && settings.showTitle){
				hasTitle = true;
				$ppt.html(unescape($caller.find('img').attr('alt')));
			}else{
				hasTitle = false;
			};
		};
	
		function _fitToViewport(width,height){
			hasBeenResized = false;
		
			_getDimensions(width,height);
			
			// Define them in case there's no resize needed
			imageWidth = width;
			imageHeight = height;

			windowHeight = $(window).height();
			windowWidth = $(window).width();
		
			if( ((pp_containerWidth > windowWidth) || (pp_containerHeight > windowHeight)) && doresize && settings.allowresize && !percentBased) {
				hasBeenResized = true;
				notFitting = true;
			
				while (notFitting){
					if((pp_containerWidth > windowWidth)){
						imageWidth = (windowWidth - 200);
						imageHeight = (height/width) * imageWidth;
					}else if((pp_containerHeight > windowHeight)){
						imageHeight = (windowHeight - 200);
						imageWidth = (width/height) * imageHeight;
					}else{
						notFitting = false;
					};

					pp_containerHeight = imageHeight;
					pp_containerWidth = imageWidth;
				};
			
				_getDimensions(imageWidth,imageHeight);
			};

			return {
				width:imageWidth,
				height:imageHeight,
				containerHeight:pp_containerHeight,
				containerWidth:pp_containerWidth,
				contentHeight:pp_contentHeight,
				contentWidth:pp_contentWidth,
				resized:hasBeenResized
			};
		};
		
		function _getDimensions(width,height){
			$pp_pic_holder.find('.pp_details').width(width).find('.pp_description').width(width).find('a.pp_close').css('width'); /* To have the correct height */
			
			// Get the container size, to resize the holder to the right dimensions
			pp_contentHeight = height + $pp_pic_holder.find('.pp_details').height() + parseFloat($pp_pic_holder.find('.pp_details').css('marginTop')) + parseFloat($pp_pic_holder.find('.pp_details').css('marginBottom'));
			pp_contentWidth = width;
			pp_containerHeight = pp_contentHeight + $pp_pic_holder.find('.ppt').height() + $pp_pic_holder.find('.pp_top').height() + $pp_pic_holder.find('.pp_bottom').height();
			pp_containerWidth = width + settings.padding;
		}
	
		function _getFileType(){
			if ($caller.attr('href').match(/youtube\.com\/watch/i)) {
				pp_type = 'youtube';
			}else if($caller.attr('href').indexOf('.mov') != -1){ 
				pp_type = 'quicktime';
			}else if($caller.attr('href').indexOf('.swf') != -1){
				pp_type = 'flash';
			}else if($caller.attr('href').indexOf('iframe') != -1){
				pp_type = 'iframe'
			}else{
				pp_type = 'image';
			}
		}
	
		function _centerPicture(){
			if ($pp_pic_holder){ if($pp_pic_holder.size() == 0){ return; }}else{ return; }; //Make sure the gallery is open

			if($.browser.opera) {
				windowHeight = window.innerHeight;
				windowWidth = window.innerWidth;
			}else{
				windowHeight = $(window).height();
				windowWidth = $(window).width();
			};
		
			if(doresize) {
				$pHeight = $pp_pic_holder.height();
				$pWidth = $pp_pic_holder.width();
				$tHeight = $ppt.height();
				
				projectedTop = (windowHeight/2) + $scrollPos['scrollTop'] - ($pHeight/2);
				if(projectedTop < 0) projectedTop = 0 + $tHeight;
				
				$pp_pic_holder.css({
					'top': projectedTop,
					'left': (windowWidth/2) + $scrollPos['scrollLeft'] - ($pWidth/2)
				});
		
				$ppt.css({
					'top' : projectedTop - $tHeight,
					'left' : (windowWidth/2) + $scrollPos['scrollLeft'] - ($pWidth/2) + (settings.padding/2)
				});
			};
		};
	
		function _preload(){
			// Hide the next/previous links if on first or last images.
			_checkPosition();
		
			if(pp_type == 'image'){
				// Set the new image
				imgPreloader = new Image();
		
				// Preload the neighbour images
				nextImage = new Image();
				if(isSet && setPosition > setCount) nextImage.src = $(imagesArray[arrayPosition + 1]).attr('href');
				prevImage = new Image();
				if(isSet && imagesArray[arrayPosition - 1]) prevImage.src = $(imagesArray[arrayPosition - 1]).attr('href');

				pp_typeMarkup = '<img id="fullResImage" src="" />';				
				$pp_pic_holder.find('#pp_full_res')[0].innerHTML = pp_typeMarkup;

				$pp_pic_holder.find('.pp_content').css('overflow','hidden');
				$pp_pic_holder.find('#fullResImage').attr('src',$caller.attr('href'));

				imgPreloader.onload = function(){
					var correctSizes = _fitToViewport(imgPreloader.width,imgPreloader.height);
					imgPreloader.width = correctSizes['width'];
					imgPreloader.height = correctSizes['height'];
					showimage(imgPreloader.width,imgPreloader.height,correctSizes["containerWidth"],correctSizes["containerHeight"],correctSizes["contentHeight"],correctSizes["contentWidth"],correctSizes["resized"]);
				};
		
				imgPreloader.src = $caller.attr('href');
			}else{
				// Get the dimensions
				movie_width = ( parseFloat(grab_param('width',$caller.attr('href'))) ) ? grab_param('width',$caller.attr('href')) : "425";
				movie_height = ( parseFloat(grab_param('height',$caller.attr('href'))) ) ? grab_param('height',$caller.attr('href')) : "344";

				// If the size is % based
				if(movie_width.indexOf('%') != -1 || movie_height.indexOf('%') != -1){
					movie_height = ($(window).height() * parseFloat(movie_height) / 100) - 100;
					movie_width = ($(window).width() * parseFloat(movie_width) / 100) - 100;
					parsentBased = true;
				}else{
					movie_height = parseFloat(movie_height);
					movie_width = parseFloat(movie_width);
				}
				
				if(pp_type == 'quicktime'){ movie_height+=13; }
				
				// Fit them to viewport
				correctSizes = _fitToViewport(movie_width,movie_height);
				
				if(pp_type == 'youtube'){
					pp_typeMarkup = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://www.youtube.com/v/'+grab_param('v',$caller.attr('href'))+'" /><embed src="http://www.youtube.com/v/'+grab_param('v',$caller.attr('href'))+'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"></embed></object>';
				}else if(pp_type == 'quicktime'){
					pp_typeMarkup = '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" height="'+correctSizes['height']+'" width="'+correctSizes['width']+'"><param name="src" value="'+$caller.attr('href')+'"><param name="autoplay" value="true"><param name="type" value="video/quicktime"><embed src="'+$caller.attr('href')+'" height="'+correctSizes['height']+'" width="'+correctSizes['width']+'" autoplay="true" type="video/quicktime" pluginspage="http://www.apple.com/quicktime/download/"></embed></object>';
				}else if(pp_type == 'flash'){
					flash_vars = $caller.attr('href');
					flash_vars = flash_vars.substring($caller.attr('href').indexOf('flashvars') + 10,$caller.attr('href').length);

					filename = $caller.attr('href');
					filename = filename.substring(0,filename.indexOf('?'));

					pp_typeMarkup = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="'+filename+'?'+flash_vars+'" /><embed src="'+filename+'?'+flash_vars+'" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="'+correctSizes['width']+'" height="'+correctSizes['height']+'"></embed></object>';
				}else if(pp_type == 'iframe'){
					movie_url = $caller.attr('href');
					movie_url = movie_url.substr(0,movie_url.indexOf('iframe')-1);

					pp_typeMarkup = '<iframe src ="'+movie_url+'" width="'+(correctSizes['width']-10)+'" height="'+(correctSizes['height']-10)+'" frameborder="no"></iframe>';
				}
				// Append HTML
				$pp_pic_holder.find('#pp_full_res')[0].innerHTML = pp_typeMarkup;
				
				// Show content
				showimage(correctSizes['width'],correctSizes['height'],correctSizes["containerWidth"],correctSizes["containerHeight"],correctSizes["contentHeight"],correctSizes["contentWidth"],correctSizes["resized"]);
			}
		};
	
		function _getScroll(){
			if (self.pageYOffset) {
				scrollTop = self.pageYOffset;
				scrollLeft = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				scrollTop = document.documentElement.scrollTop;
				scrollLeft = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				scrollTop = document.body.scrollTop;
				scrollLeft = document.body.scrollLeft;	
			}
			
			return {scrollTop:scrollTop,scrollLeft:scrollLeft};
		};
	
		function _resizeOverlay() {
			$('div.pp_overlay').css({
				'height':$(document).height(),
				'width':$(window).width()
			});
		};
	
		function _buildOverlay(){
			toInject = "";
			
			// Build the background overlay div
			toInject += "<div class='pp_overlay'></div>";
			
			// Define the markup to append, depending on the content type.
			if(pp_type == 'image'){
				pp_typeMarkup = '<img id="fullResImage" src="" />';
			}else{
				pp_typeMarkup = '';
			}
			
			// Basic HTML for the picture holder
			toInject += '<div class="pp_pic_holder"><div class="pp_top"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div><div class="pp_content"><a href="#" class="pp_expand" title="Expand the image">Expand</a><div class="pp_loaderIcon"></div><div class="pp_hoverContainer"><a class="pp_next" href="#">next</a><a class="pp_previous" href="#">previous</a></div><div id="pp_full_res">'+ pp_typeMarkup +'</div><div class="pp_details clearfix"><p class="pp_description"></p><a class="pp_close" href="#">Close</a><div class="pp_nav"><a href="#" class="pp_arrow_previous">Previous</a><p class="currentTextHolder">0'+settings.counter_separator_label+'0</p><a href="#" class="pp_arrow_next">Next</a></div></div></div><div class="pp_bottom"><div class="pp_left"></div><div class="pp_middle"></div><div class="pp_right"></div></div></div>';
			
			// Basic html for the title holder
			//toInject += '<div class="ppt"></div>';
			
			$('body').append(toInject);
			
			// Set my global selectors
			$pp_pic_holder = $('.pp_pic_holder');
			$ppt = $('.ppt');
			
			$('div.pp_overlay').css('height',$(document).height()).bind('click',function(){
				close();
			});

			$pp_pic_holder.css({'opacity': 0}).addClass(settings.theme);

			$('a.pp_close').bind('click',function(){ close(); return false; });

			$('a.pp_expand').bind('click',function(){				
				$this = $(this);
				
				// Expand the image
				if($this.hasClass('pp_expand')){
					$this.removeClass('pp_expand').addClass('pp_contract');
					doresize = false;
				}else{
					$this.removeClass('pp_contract').addClass('pp_expand');
					doresize = true;
				};
			
				_hideContent();
				
				$pp_pic_holder.find('.pp_hoverContainer, #pp_full_res, .pp_details').fadeOut(settings.animationSpeed,function(){
					_preload();
				});
		
				return false;	
			});
		
			$pp_pic_holder.find('.pp_previous, .pp_arrow_previous').bind('click',function(){
				changePicture('previous');
				return false;
			});
		
			$pp_pic_holder.find('.pp_next, .pp_arrow_next').bind('click',function(){
				changePicture('next');
				return false;
			});

			$pp_pic_holder.find('.pp_hoverContainer').css({
				'margin-left': settings.padding/2
			});
		
			// If it's not a set, hide the links
			if(!isSet) {
				$pp_pic_holder.find('.pp_hoverContainer,.pp_nav').hide();
			};


			// To fix the bug with IE select boxes
			if($.browser.msie && $.browser.version == 6){
				$('body').addClass('ie6');
				$('select').css('visibility','hidden');
			};

			// Then fade it in
			$('div.pp_overlay').css('opacity',0).fadeTo(settings.animationSpeed,settings.opacity, function(){
				$pp_pic_holder.css('opacity',0).fadeIn(settings.animationSpeed,function(){
					$pp_pic_holder.attr('style','left:'+$pp_pic_holder.css('left')+';top:'+$pp_pic_holder.css('top')+';');
					_preload();
				});
			});
		};
	};
	
	function grab_param(name,url){
	  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	  var regexS = "[\\?&]"+name+"=([^&#]*)";
	  var regex = new RegExp( regexS );
	  var results = regex.exec( url );
	  if( results == null )
	    return "";
	  else
	    return results[1];
	}
})(jQuery);
