var $jquerynoConflict = jQuery.noConflict();

$jquerynoConflict(document).ready(
    function()
    {


        var meksyk_daty = Array();
        var meksyk_aktualna_data = new Date();
        var meksyk_i = 0;
        var meksyk_adres_obrazka = '';
        var meksyk_ile_aktualnych = 0;

        function meksyk_inicjalizacja()
        {

            meksyk_temp = $jquerynoConflict("#meksyk_data_przedstawienia_1").val();
            meksyk_daty.push(meksyk_temp);

            meksyk_temp = $jquerynoConflict("#meksyk_data_przedstawienia_2").val();
            meksyk_daty.push(meksyk_temp);

            meksyk_temp = $jquerynoConflict("#meksyk_data_przedstawienia_3").val();
            meksyk_daty.push(meksyk_temp);

            meksyk_temp = $jquerynoConflict("#meksyk_data_przedstawienia_4").val();
            meksyk_daty.push(meksyk_temp);

            meksyk_temp = $jquerynoConflict("#meksyk_data_przedstawienia_5").val();
            meksyk_daty.push(meksyk_temp);

            meksyk_temp = $jquerynoConflict("#meksyk_data_przedstawienia_6").val();
            meksyk_daty.push(meksyk_temp);

            meksyk_temp = $jquerynoConflict("#meksyk_data_przedstawienia_7").val();
            meksyk_daty.push(meksyk_temp);

            meksyk_adres_obrazka = $jquerynoConflict("#meksyk_adres_numeru").val();

            meksyk_odlicz_czas();
        }

        function meksyk_odlicz_czas(){
            setTimeout(function() {
                meksyk_odlicz_czas();
            }, 1000);

            meksyk_ile_aktualnych = 0;
            for(x in meksyk_daty)
            {
                var meksyk_data = new Date(meksyk_daty[x]);
                meksyk_aktualna_data = new Date();
                if(meksyk_aktualna_data.getTime() + 1000 < meksyk_data.getTime())
                {
                    if(meksyk_ile_aktualnych == 0)
                    {
                        roznica = (meksyk_data.getTime() - meksyk_aktualna_data.getTime()) / 1000;
                        ile_godzin = Math.floor(roznica / 60 / 60);
                        ile_minut = Math.floor((roznica - (ile_godzin * 60 * 60) ) / 60);
                        ile_sekund = Math.floor(roznica - (ile_godzin * 60 * 60) - (ile_minut * 60));

                        temp = Math.floor(ile_godzin / 24);
                        ile_dni = temp;
                        ile_godzin = ile_godzin - (temp * 24);

                        meksyk_temp = $jquerynoConflict("#meksyk_czas_ile_dni");
                        temp = ile_dni.toString();
                        meksyk_temp.html('');
                        for(meksyk_i = 0; meksyk_i < temp.length; meksyk_i++)
                        {
                            meksyk_temp.append('<img src="' + meksyk_adres_obrazka.replace('XXX', temp[meksyk_i]) + '" style="margin: 0px; padding: 0px; border: 0px;" alt="" />');
                        }


                        meksyk_temp = $jquerynoConflict("#meksyk_czas_ile_godzin");
                        temp = ile_godzin.toString();
                        meksyk_temp.html('');
                        for(meksyk_i = 0; meksyk_i < temp.length; meksyk_i++)
                        {
                            meksyk_temp.append('<img src="' + meksyk_adres_obrazka.replace('XXX', temp[meksyk_i]) + '" style="margin: 0px; padding: 0px; border: 0px;" alt="" />');
                        }


                        meksyk_temp = $jquerynoConflict("#meksyk_czas_ile_minut");
                        temp = ile_minut.toString();
                        meksyk_temp.html('');
                        for(meksyk_i = 0; meksyk_i < temp.length; meksyk_i++)
                        {
                            meksyk_temp.append('<img src="' + meksyk_adres_obrazka.replace('XXX', temp[meksyk_i]) + '" style="margin: 0px; padding: 0px; border: 0px;" alt="" />');
                        }


                        meksyk_temp = $jquerynoConflict("#meksyk_czas_ile_sekund");
                        temp = ile_sekund.toString();
                        meksyk_temp.html('');
                        for(meksyk_i = 0; meksyk_i < temp.length; meksyk_i++)
                        {
                            meksyk_temp.append('<img src="' + meksyk_adres_obrazka.replace('XXX', temp[meksyk_i]) + '" style="margin: 0px; padding: 0px; border: 0px;" alt="" />');
                        }

                        temp = (ile_sekund) + (ile_minut * 60) + (ile_godzin * 60 * 60) + (ile_dni * 60 * 60 * 24);
                        if(temp > (3 * 60 * 60 * 24) )
                        {
                            $jquerynoConflict("#meksyk_piesek_1").show();
                            $jquerynoConflict("#meksyk_piesek_2").hide();
                            $jquerynoConflict("#meksyk_piesek_2").hide();
                        }
                        else if(temp > (60 * 60 * 24) )
                        {
                            $jquerynoConflict("#meksyk_piesek_1").hide();
                            $jquerynoConflict("#meksyk_piesek_2").show();
                            $jquerynoConflict("#meksyk_piesek_3").hide();
                        }
                        else
                        {
                            $jquerynoConflict("#meksyk_piesek_1").hide();
                            $jquerynoConflict("#meksyk_piesek_2").hide();
                            $jquerynoConflict("#meksyk_piesek_3").show();
                        }


                    }
                    meksyk_ile_aktualnych++;
                    
                }

            }

            if(meksyk_ile_aktualnych == 0)
            {
                $jquerynoConflict("#meksyk_czas_koniec").show();
                $jquerynoConflict("#meksyk_czas").hide();

                $jquerynoConflict("#meksyk_piesek_1").show();
                $jquerynoConflict("#meksyk_piesek_2").hide();
                $jquerynoConflict("#meksyk_piesek_3").hide();
            }
            else
            {
                $jquerynoConflict("#meksyk_czas_koniec").hide();
                $jquerynoConflict("#meksyk_czas").show();
            }
            
        }

        meksyk_inicjalizacja();

        //

        $jquerynoConflict('.meksyk_obrazki').each(function() {
            $jquerynoConflict(this).hover(function() {

                id = $jquerynoConflict(this).attr('id');
                pozycja = id.search('meksyk_obrazki_a_');
                
                if(pozycja != -1)
                {
                    id = id.replace('meksyk_obrazki_a_', 'meksyk_div_');
                    $jquerynoConflict("#" + id).toggle(750);
                }
            },
            function() {
                id = $jquerynoConflict(this).attr('id');
                pozycja = id.search('meksyk_obrazki_a_');
                if(pozycja != -1)
                {
                    id = id.replace('meksyk_obrazki_a_', 'meksyk_div_');
                    $jquerynoConflict("#" + id).toggle(300);
                }
            });
        });

    /*
        var ile = 0;
        var tmr;
        var ktory = 1;
        var czas = 2500;
	

        function Inicjacja()
        {
            $jquerynoConflict(".div_tresc").each(function() {
                ile++;
            });

            if(ile == 0) return;
            
            ktory = Math.floor(ile * Math.random()) + 1;
            $jquerynoConflict("#div_" + ktory).show();

            pierwszy = $jquerynoConflict(".div_tresc:visible");
            adres_do_tla = pierwszy.children("a").children("img").attr("src");
            pierwszy.parent().css('background-image', 'url(' + adres_do_tla + ')');

            ktory++;
            tmr = setTimeout(function() {
                Zmien();
            }, 5000);
        }
	
        function Zmien()
        {
            
            if(ile == 0) return;
            if(ktory > ile) ktory = 1;
            if(ktory <= 0) ktory = ile;

            pierwszy = $jquerynoConflict(".div_tresc:visible");
            adres_do_tla = pierwszy.children("a").children("img").attr("src");
            pierwszy.parent().css('background-image', 'url(' + adres_do_tla + ')');

            $jquerynoConflict(".div_tresc").each(function() {
                $jquerynoConflict(this).hide();
                $jquerynoConflict(this).children("a").children("img").stop().animate({
                    opacity: 0
                }, 1);
            });


            $jquerynoConflict("#div_" + ktory).show().children("a").children("img").animate({
                opacity: 1
            }, 2000, function(){
  
                });

            ktory++;

            tmr = setTimeout(function() {
                Zmien();
            }, 2000 + czas);
            
        }



        $jquerynoConflict('.div_tresc').each(function() {
            $jquerynoConflict(this).hover(function() {
                clearTimeout(tmr);
            },
            function() {
                clearTimeout(tmr);
                tmr = setTimeout(function() {
                    Zmien();
                }, czas);
            });
        });

        $jquerynoConflict(".zmien_odnosnik").live('click', function(){
            clearTimeout(tmr);
            var id = $jquerynoConflict(this).attr('id');
            id = id.replace("zmien_odnosnik_", "");
            ktory = id;
            Zmien();
        });

        $jquerynoConflict(".rotacja_start").live('click', function(){
            clearTimeout(tmr);
            tmr = setTimeout(function() {
                Zmien();
            }, czas);
        });

        $jquerynoConflict(".rotacja_stop").live('click', function(){
            clearTimeout(tmr);
        });

        $jquerynoConflict("#rotacja_nastepny").live('click', function(){
            clearTimeout(tmr);
            Zmien();
        });

        $jquerynoConflict("#rotacja_poprzedni").live('click', function(){
            clearTimeout(tmr);
            ktory = ktory - 2;
            if(ktory <= 0) ktory = ile;
            Zmien();
        });

        var zmiana_ktory = null;
        $jquerynoConflict('.zmien_boks').each(function() {
            $jquerynoConflict(this).hover(function() {
                clearTimeout(tmr);
                id = $jquerynoConflict(this).attr('id');
                id = id.replace("zmien_boks_", "");

                zmiana_ktory = $jquerynoConflict(".div_tresc:visible");
                zmiana_ktory.parent().css('background-image', 'none');

                $jquerynoConflict(".div_tresc:visible").each(function() {
                    $jquerynoConflict(this).children("a").children("img").stop().animate({
                        opacity: 0
                    }, 500, function(){
                        zmiana_ktory.hide();
                        $jquerynoConflict("#box1").removeClass("box1");
                        $jquerynoConflict("#box1").addClass("box2");
                        $jquerynoConflict("#boks_tresc").html($jquerynoConflict("#boks_tresc_" + id).html());
                        $jquerynoConflict("#boks_tresc").show();
                    });
                });
            },
            function() {
                $jquerynoConflict("#boks_tresc").hide();
                $jquerynoConflict("#box1").removeClass("box2");
                $jquerynoConflict("#box1").addClass("box1");
                zmiana_ktory.show();
                zmiana_ktory.children("a").children("img").stop().animate({
                    opacity: 1
                }, 1000, function(){
                    adres_do_tla = zmiana_ktory.children("a").children("img").attr("src");
                    zmiana_ktory.parent().css('background-image', 'url(' + adres_do_tla + ')');
                });
            
                clearTimeout(tmr);
                ktory--;
                tmr = setTimeout(function() {
                    Zmien();
                }, 2500);
            });
        });

        Inicjacja();*/
    }
    );


