var flashvars = {};
var params = {
    wmode:"transparent"
};
var attributes = {};
    

function sprawdz_formularz(AForm)
{
    if(AForm.MailMessContent.value == "")
    {
        alert("Prosze wypelnic pole wiadomosci.");
        return false;
    }
    if(AForm.MailMessName.value == "")
    {
        alert("Prosze wypelnic pole imie.");
        return false;
    }
    reg = /^[a-zA-Z0-9aceln�szzACELN�SZZ\.]{1,30}@[a-zA-Z0-9aceln�szzACELN�SZZ]+(\.[a-zA-Z0-9aceln�szzACELN�SZZ]+)+$/;
    wynik  = AForm.MailMessEmail.value.match(reg);
    if (wynik  == null) {
        alert("Prosze podac poprawny adres email. " +
            "Poprawny adres musi zawierac malpe " +
            "oraz co najmniej dwa czlony nazwy serwera, " +
            "np. a@b.c lub ala@ma.kota.czarnego.com.");
        return false;
    }
    return true;
}


function logos(prev_i,friend)
{
    var i=prev_i;
    var next_i=prev_i+1;
    var id = new Array("friend1","friend2","friend3");
    var firma = new Array("zen_dezign","allegro","bitexpert","epic","fcs","hcp","integra","lech","pizza_express","raczkowski","rms","simp","trendy","unibis","whitenergy","zdz","aplusw","afekt","dreampen","enan","ghands","hemigraf","kodkrowa","trytonik","motis","neter","poznan1","poznan2","wikor","sorus","ic","koszuty","vitriol","mdk","saenger","dkf");

    $('#'+id[friend]).animate( {
        opacity:0,
        top: '-=10'
    }, 700, function () {
        $(this).html('<a href="/friends" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage(\'Image'+friend+'\',\'\',\'/img/logotypy/logo_'+firma[i]+'_H.jpg\',1)"><img id="Image'+friend+'" src="/img/logotypy/logo_'+firma[i]+'.jpg" alt=""></a>');
        $(this).animate({
            opacity:1,
            top: '+=10'
        }, 700);
    });

    if(next_i == 36) {
        next_i = 0;
    }
    setTimeout("logos("+next_i+","+friend+")",9000);

}

function switchDescription(id)
{
    if($('#project_description1').css('display') == "block")
    {
        $('#project_description1').css('display', 'none');
    }
    if($('#project_description2').css('display') == "block")
    {
        $('#project_description2').css('display', 'none');
    }
    if($('#project_description3').css('display') == "block")
    {
        $('#project_description3').css('display', 'none');
    }

    $('#'+id).css('display', 'block');
}

function showMeFlash(id)
{
    $('#'+id).style.visibility = 'hidden';
}

function collapseFrame(obj, param) {
    var frame_id = $(obj).parents('.frame')
    .map(function () {
        return this.id;
    }).get();
    content_id = frame_id+"_content";
    btn_id = frame_id+"_collapse_btn";

    if ($('#'+frame_id).css('height')!='55px' || param=='expand') {
        $.ajax({
            type: "POST",
            url: "/sites/writeBoxes/",
            data: 'id='+frame_id+'&t=collapse'
        });

        $('#'+frame_id).animate({
            height: 55
        }, 'slow');
        $('#'+frame_id).parent().animate({
            height: 75
        }, 'slow');
        $('#'+frame_id).parent().removeClass('expand');
        $('#'+frame_id).parent().addClass('collapse');
        $('#'+content_id).slideUp();
        $(obj).html('<img src="/img/ptaszek.gif" >');
    } else {
        if(frame_id == "news_frame")
        {
            height_frame = {
                height:418
            };
            height_id = {
                height:440
            };
        }
        if(frame_id == "kontakt_frame")
        {
            height_frame = {
                height:208
            };
            height_id = {
                height:240
            };
        }
        if(frame_id == "newsletter_frame")
        {
            height_frame = {
                height:98
            };
            height_id = {
                height:110
            };
        }
        $.ajax({
            type: "POST",
            url: "/sites/writeBoxes/",
            data: 'id='+frame_id+'&t=expand'
        });

        $('#'+frame_id).animate(height_frame, 'slow');
        $('#'+frame_id).parent().animate(height_id, 'slow');
        $('#'+frame_id).parent().removeClass('collapse');
        $('#'+frame_id).parent().addClass('expand');
        $('#'+content_id).slideDown();
        $(obj).html('<img src="/img/ptaszek_up.gif" >');
    }
}

function showAll()
{
    $("#maska").show();
    $(document).ready(function () {
       
        $("#maska").mousemove(function() {
            $(this).animate({
                opacity: 0
            }, 'slow', function() {
                $(this).remove();
                $('body').load(function () {
                    MM_preloadImages('/img/nav_onas_over.jpg','/img/nav_portfolio_over.jpg','/img/nav_oferta_over.jpg','/img/nav_kontakt_over.jpg');
                });
            }
            );
        });
    });
}


function MM_swapImgRestore() { //v3.0
    var i,x,a=document.MM_sr;
    for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_preloadImages() { //v3.0
    var d=document;
    if(d.images){
        if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
        for(i=0; i<a.length; i++)
            if (a[i].indexOf("#")!=0){
                d.MM_p[j]=new Image;
                d.MM_p[j++].src=a[i];
            }
    }
}


function MM_findObj(n, d) { //v4.01
    var p,i,x;
    if(!d) d=document;
    if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document;
        n=n.substring(0,p);
    }
    if(!(x=d[n])&&d.all) x=d.all[n];
    for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n);
    return x;
}


function MM_swapImage() { //v3.0
    var i,j=0,x,a=MM_swapImage.arguments;
    document.MM_sr=new Array;
    for(i=0;i<(a.length-2);i+=3)
        if ((x=MM_findObj(a[i]))!=null){
            document.MM_sr[j++]=x;
            if(!x.oSrc) x.oSrc=x.src;
            x.src=a[i+2];
        }
}



function show_hide(id)
{
    t=document.getElementsByName('I'+id);
    count=t.length;
    for(i=0;i<count;i++) {

        if( t[i].style.display == 'none' )
        {
            t[i].style.display = 'block';
        }
        else
        {
            t[i].style.display = 'none';
        };
    }

}

function show(id)
{
    t=document.getElementsByName('I'+id);
    count=t.length;
    for(i=0;i<count;i++) {
        t[i].style.display = 'block';
    }

}

function hide(id)
{
    t=document.getElementsByName('I'+id);
    count=t.length;
    for(i=0;i<count;i++) {
        t[i].style.display = 'none';
    }

}

function boldFunc(id)
{
    t=document.getElementById('II'+id);
    t.style.color='#333';
    t.style.fontWeight='bold';
    t.style.background="";

}

function blueFunc(id)
{
    t=document.getElementById('II'+id);
    t.style.color='#0096FB';
}

function close_message()
{
    if($('#flashMessage'))
    {
        setTimeout("$('#flashMessage').animate({opacity:0}, 500);",2000);
    }
}

/****** loga - oferta ******/
var config = {width: 600, height: 250};

function logosChanger() {
    
    $(document).ready(function() {
        $("ul#banner").css({
            'position':'relative',
            'height': config.height + 'px',
            'width': config.width + 'px',
            'overflow':'hidden'
        });

        $("ul#banner li").each(function(i){
            $(this).css({
                'position':'absolute',
                'top':'0',
                'left':i*config.width +'px'
            });
            $(this).attr("title",i+1);
            $(this).children("a").after("<p>"+$(this).children("a").children("img").attr("alt")+"</p>");
        });

        $("ul#banner li:first").addClass("selected");
        $("ul#banner li:first").css("display", "block");
        $("ul#banner li img").css({
            'border': '0px solid black',
            'height': config.height + 'px',
            'width': config.width + 'px'
        });

        $(".buttons").css('width', config.width + 'px');
        $("#prevB").css('left', '3px');
        $("#nextB").css('right', '3px');
        $("#prevB").mousedown(function() {
             $(this).animate({'left': '0px'}, 100).animate({'left': '3px'}, 100);
        });
        $("#nextB").mousedown(function() {
             $(this).animate({'right': '0px'}, 100).animate({'right': '3px'}, 100);
        });
        
        $(".button").hover(function() {
           $(this).animate({'top': '2px', 'bottom': '0px'}, 100);
        }, function() {
           $(this).animate({'bottom': '2px', 'top': '0px'}, 100);
        });
       
        $("#nextB").click(function() {
            next(true);
        });

        $("#prevB").click(function() {
            prev(true);
        });

        setTimeout( function(){
           next(false)
        }, 8000);

    });
}


function next(clicked) {  
    var i = parseInt($("ul#banner li.selected").attr("title"));
    if (LastElement(i)){
        $("ul#banner li[title='"+NextElement(i)+"']").css('left', config.width + 'px');
    }
    if (parseInt($("ul#banner li[title='"+NextElement(i)+"']").css('left').replace(/px/i, '')) % config.width != 0) {
        $("ul#banner li[title='"+NextElement(i)+"']").css('left', config.width + 'px');
    }
    $("ul#banner li[title='"+i+"']").removeClass("selected");
    //$("ul#banner li[title='"+i+"']").css("display", 'none');
    $("ul#banner li[title='"+(NextElement(i))+"']").addClass("selected");
    $("ul#banner li[title='"+(NextElement(i))+"']").css("display", "block");
    $("ul#banner li").each(function(i){
        var newLeft = parseInt( $(this).css("left").replace(/px/i, '') )-(config.width);
        $(this).animate({
            'left':newLeft+'px'
        }, 500);
    }); 
   if (!clicked) {
        setTimeout( function(){
            next()
        }, 8000);
    }
}

function prev(clicked) {    
    var i = parseInt($("ul#banner li.selected").attr("title"));
    if (FirstElement(i)){
        $("ul#banner li[title='"+PrevElement(i)+"']").css('left','-'+config.width+'px');
    }
    if (parseInt($("ul#banner li[title='"+PrevElement(i)+"']").css('left').replace(/px/i, '')) % config.width != 0) {
        $("ul#banner li[title='"+PrevElement(i)+"']").css('left', '-'+config.width + 'px');
    }
    $("ul#banner li[title='"+i+"']").removeClass("selected");
    //$("ul#banner li[title='"+i+"']").css("display", 'none');
    $("ul#banner li[title='"+(PrevElement(i))+"']").addClass("selected");
    $("ul#banner li[title='"+(PrevElement(i))+"']").css("display", "block");
    $("ul#banner li").each(function(i){
        var newLeft = parseInt( $(this).css("left").replace(/px/i, '') )+(config.width);
        $(this).animate({
            'left':newLeft+'px'
        }, 500);
    });   
   if (!clicked) {
        setTimeout( function(){
            next()
        }, 8000);
    }
}

function NextElement(index) {
    if(index < parseInt($("ul#banner li:last").attr("title"))) {
        return index + 1;
    } else {
        return 1;
    }
}

function PrevElement(index) {
    if(index > parseInt($("ul#banner li:first").attr("title"))) {
        return index - 1;
    } else {
        return parseInt($("ul#banner li:last").attr("title"));
    }
}

function LastElement(index) {
    return (parseInt($("ul#banner li[title='"+NextElement(index)+"']").css("left").replace(/px/i, '')) <= (1 - parseInt($("ul#banner li:last").attr("title")))*(config.width));
}

function FirstElement(index) {   
    return (parseInt($("ul#banner li[title='"+PrevElement(index)+"']").css("left").replace(/px/i, '')) >= (parseInt($("ul#banner li:last").attr("title")) -1 )*(config.width));
}




/**************end loga - oferta *****************************/


$(document).ready(function(){

    $('.frame').mouseover(function() {
        //$(this).css('borderColor', '#CCC');
        $(this).removeClass('off').addClass('on');
        $('#'+this.id+'_collapse_btn').show();
    //$('.collapse_btn').show();
    });
    $('.frame').mouseout(function () {
        //var tmp_id = this.id;
        //$('#'+tmp_id).animate( {borderLeftColor: '#F7F7F7', borderRightColor: '#F7F7F7', borderTopColor: '#F7F7F7', borderBottomColor: '#F7F7F7'}, 3000).delay(3000);
        // setTimeout( function () {
        $(this).removeClass('on').addClass('off');
        //$('#'+tmp_id).removeClass('on', 3000).delay(3000);

        //}, 1000);
        $('#'+this.id+'_collapse_btn').hide();
    //$('.collapse_btn').hide();
    }
    );

    $('.collapse').children('.frame').css('height', '55px');
    $('.collapse').css('height', '75px');
    $('.collapse').children('.frame').children('.collapse_btn').children('a').html('<img src="/img/ptaszek.gif" >');
    $('.collapse').children('.frame').children('.box').children('div').hide();

    logos(1,0);
    setTimeout("logos(12,1);",2000);
    setTimeout("logos(24,2);",4000);
    close_message();
});
