N = navigator.userAgent;
N = N.toLowerCase();
isIE      = ((N.indexOf("msie") != -1) && (N.indexOf("opera") == -1));
isOpera   = (N.indexOf("opera") != -1);
isMac     = (N.indexOf("mac") != -1);
isFireFox = (N.indexOf("firefox") != -1);
isSafari  = (N.indexOf("safari") != -1);
isGecko   = (navigator.product == "Gecko");
isIE6 = (N.indexOf("msie 6") != -1);

function add2fav(sender) {
    if (isIE)
    {
        window.external.AddFavorite(self.location, document.title);
        return false;
    }
    else
    if (isSafari)
    {
        sender.href  = self.location;
        sender.title = document.title;
        return true;
    }
    else
    if (isGecko)
    {
        window.sidebar.addPanel(document.title, self.location, "");
        return false;
    }
    else
    if (isOpera)
    {
        sender.href  = self.location;
        sender.title = document.title;
        alert(sender.href);
        return true;
    }
}


//rejestracja sklepu - uzyj danych osobowych do rejestracji sklepu
var classname_err_msg = 'error';

//prostsze pobieranie de...
function de(id) {
    return document.getElementById(id);
}
function dc(name) {
    return document.getElementsByClassName(name);
}

function putFlash(sPath, iWidth, iHeight, sID) {
    with (document) {
        write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+iWidth+'" height="'+iHeight+'" id="'+sID+'">');
        write('  <param name="movie" value="'+sPath+'" />');
        write('  <param name="quality" value="high" />');
        write('  <param name="wmode" value="transparent" />');
        write('  <param name="menu" value="false" />');
        write('  <embed src="'+sPath+'" quality="high" wmode="transparent" menu="false" width="'+iWidth+'" height="'+iHeight+'" swLiveConnect=true name="'+sID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
        write('</object>');
    }
}


//wysuwanie/wsuwanie menu
var menu_show_flag = false;
function showSubMenu() {

    if (menu_show_flag == false) {
        $('ul#sub_menu').slideDown('slow');
        menu_show_flag = true;
        //var flowers = document.getElementById('flowers');
        //flowers.style.backgroundPosition = '0 -25px';
    }
}
function hideSubMenu() {
    if (menu_show_flag == true) {
        $('ul#sub_menu').slideUp('slow');
        menu_show_flag = false;

        //var flowers = document.getElementById('flowers');
        //flowers.style.backgroundPosition = '0 0';
    }
}

//showImage

var ind = 1;
function showImage(sender, index) {
    lImg = document.getElementById("largeimage");

    if (!(!lImg)) {
        lImg.src = sender.href;
        lImg.name = sender.rel;
        //lImg.alt = sender.childNodes[0].alt;
    }
    ind = index;
}

function prev() {
    if (ind==1)
    ind = ln;
    else
    ind--;
    tImg = document.getElementById("pic"+ind);
    if (!(!tImg))
    showImage(tImg, ind);
}
function next() {
    if (ind==ln)
    ind = 1;
    else
    ind++;
    tImg = document.getElementById("pic"+ind);
    if (!(!tImg))
    showImage(tImg, ind);
}
var timer2;
var slide_action = 'off';
function slide(action) {
    if (slide_action == 'on' && action == 'on') {
        slide_action = 'off';
        stopSlid();
        return;
    } 

    slide_action = 'on';
    
    if (ind == ln)
    ind = 1;
    else
    ind++;
    
    tImg = document.getElementById("pic"+ind);
    if (!(!tImg))
    showImage(tImg, ind);

    timer2 = setTimeout("slide(1);", 2120);

}

function stopSlid() {
    clearTimeout(timer2)
}

function popupImg(sender) {
    
    if (slide_action == 'on') {
        slide_action = 'off';
        stopSlid();
    } 

    obj = document.getElementById("divPop");
    if (!(!obj))
    obj.parentNode.removeChild(obj);

    divPop = document.createElement('div');
    divPop.id = 'divPop';
    divPop.style.diplay = 'block';
    divPop.style.backgroundColor = '#ffffff';
    divPop.style.position = 'absolute';
    divPop.style.left = '160px';
    divPop.style.top = '150px';
    divPop.style.padding = '5px';
    divPop.style.zIndex = '11';
    divPop.onclick = function () {
        this.parentNode.removeChild(this);
    }
    de('main').appendChild(divPop);
    //getScrolling('divPop');
    //new_src = sender.src.replace('web', 'web_large');
    /*//tworzenie obrazka
    tImg = document.createElement('img');
    tImg.src = sender.src.replace('web', 'web_large');
    tImg.style.width = tImg.width+'px';
    tImg.style.height = tImg.height+'px';
    tImg.style.cursor = 'pointer';
    tImg.alt = tImg.src;
    divPop.appendChild(tImg);*/
    divPop.innerHTML = '<img src="'+sender.name+'" onclick="hide_obj(\'popupImg\')" />';
}
/*function popupImg(sender) {
//lImg = document.getElementById("largeimage");
//show_obj('popupImg');
getScrolling('popupImg');
divPop = document.getElementById('popupImg');
//divPop.style.diplay = 'block';
divPop.style.width = (sender.width+10)+'px';
divPop.style.height = (sender.height+20)+'px';

new_src = sender.src.replace('web', 'web_large');

//tworzenie obrazka
//    tImg = document.createElement('img');
//    tImg.alt = 'close';
//    tImg.src = sender.src.replace('web', 'web_large');
//    tImg.width = sender.width+'px';
//    tImg.height = sender.height+'px';
//    alert(tImg);
//    divPop.appendChild(tImg);
divPop.innerHTML = '<img src="'+new_src+'" onclick="hide_obj(\'popupImg\')" />';

}*/


function getScrolling(divName) {
    var x = 0; var y = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape compliant
        y = window.pageYOffset;
        x = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft ||
    document.body.scrollTop ) ) {
        //DOM compliant
        y = document.body.scrollTop;
        x = document.body.scrollLeft;
    } else if( document.documentElement &&
    ( document.documentElement.scrollLeft ||
    document.documentElement.scrollTop ) ) {
        //IE6 standards compliant mode
        y = document.documentElement.scrollTop;
        x = document.documentElement.scrollLeft;
    }
    //alert(x+","+y);
    showMyDiv(divName, y);
    //return x+","+y;
    return y;
}

function showMyDiv(name, y) {
    //show_obj(name);
    //centrowanie wzledem poziomu
    var main = de("main");
    leftVal = (Math.round(main.offsetWidth/2))-(Math.round(de(name).offsetWidth/2));

    de(name).style.top = (y+160) +"px";
    de(name).style.left = leftVal +"px";
}



function updateObjects(fname, imgname, spname, fsize, wmax, hmax) {

    inputObj = document.getElementById(fname);
    //	alert(inputObj);
    if (document.all) {
        inputObj.onchange = function() { imageChange(fname, imgname, spname, fsize, wmax, hmax) };
    } else {
        inputObj.onclick = function() { imageChange(fname, imgname, spname, fsize, wmax, hmax) };
    }
}


function hide_obj(name) {
    var agt=navigator.userAgent.toLowerCase();
    var is_ie5 = ((parseInt(navigator.appVersion) == 4) && (agt.indexOf("msie 5.0")!=-1) && (agt.indexOf("opera") == -1));

    if (document.getElementById && !is_ie5) {
        obj=document.getElementById(name).style.visibility = "hidden";
        document.getElementById(name).style.display = "none";
    } else if (document.layers) {
        obj=document.layers[name].visibility = "hide";
        document.layers[name].display = "none";
    } else if (document.all) {
        obj=document.all[name].style.visibility = "hidden";
        document.all[name].display = "none";
    } else {
        obj=false;
    }
}

function show_obj(name) {
    var agt=navigator.userAgent.toLowerCase();
    var is_ie5 = ((parseInt(navigator.appVersion) == 4) && (agt.indexOf("msie 5.0")!=-1) && (agt.indexOf("opera") == -1));
    if (document.getElementById && !is_ie5) {
        obj=document.getElementById(name).style.visibility = "visible";
        document.getElementById(name).style.display = "inline";
    } else if (document.layers) {
        obj=document.layers[name].visibility = "show";
        document.layers[name].display = "inline";
    } else if (document.all) {
        obj=document.all[name].style.visibility = "visible";
        document.all[name].display = "inline";
    } else {
        obj=false;
    }
}



var timer;

function moveLayer(direct) {

    cntPics = ln;

    var obj = document.getElementById("thumbs_container"); //ogolny div
    var objDiv = document.getElementById("thumbs"); //div - parent tabelki

    //var objTable = document.getElementById("tablePics"); //table ze zdjeciami
    var widthTable = objDiv.offsetWidth;
    var iloscPx = 5;
    //cntPics ilosc zdjec w tabeli * margin

    //alert(widthTable +" df "+ objDiv.style.left);

    //dalej nie przewijam...
    var maxLeft = (widthTable-373)*-1;
    var maxRight = -1;

    //alert(parseInt(objDiv.style.left));
    if (direct == 'leftside') {
        if (parseInt(objDiv.style.left) <= maxLeft) {
            stopScroller();
        } else {
            objDiv.style.left = parseInt(objDiv.style.left)-iloscPx +"px";
        }
        if (objDiv.style.left > maxLeft) {
            stopScroller();
        }
    } else {
        if (parseInt(objDiv.style.left) < maxRight) {
            objDiv.style.left=parseInt(objDiv.style.left)+iloscPx +"px";
        } else {
            stopScroller();
        }
    }
    timer = setTimeout("moveLayer('"+direct+"', '"+cntPics+"');", 20);
}
function stopScroller() {
    clearTimeout(timer)
}

// ____________________
function test_link() {
    $('#external_links a').click(function() {
        return confirm('You are going to visit: ' + this.href);
    });
}

function newsletter() {
    email = $('#newsletter_form').val();
    var regex = /^((\"[^\"\f\n\r\t\v\b]+\")|([\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+(\.[\w\!\#\$\%\&'\*\+\-\~\/\^\`\|\{\}]+)*))@((\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\-])+\.)+[A-Za-z\-]+))$/;

    if (email != '' && !regex.test(email)) {
        alert ("Proper email is required!");
        return false;
    } else {
        var type = 'newsletter';
        $.ajax({
            type: "POST",
            url: 'index.php/ident,response/?id='+escape(email)+'&type='+type,
            dataType: "html",
            success: function(xml) {
                $('#newsletter_holder').html(xml);
            },
            error: function(){ alert("Ajax error"); }
        });
    }
}