$(document).ready(function(){

   // var mainurl ="/capturelight.cz";
var mainurl ="";
    //$(document).pngFix();
    $("#galbigpic").pngFix();
    //$("#footer").pngFix();

    var pos = 0;
    var links = $(".galcontent .onepicbox a").length;




    $("#application-error").hide();
  
    $("#show-error").click(function (){
        $("#application-error").toggle("slow");
								   
    });
    if ($(".homesmallphoto").length > 0) {


        var lang = $(".widefoto a").attr("rel");
        var i = 0;
        $(".homesmallphoto a").each(function(){
            i++;
            $(this).attr("name",i);
            var newhtml = "";
            if($(this).attr("rel") > 0) {
                if(lang == "cz") {
                    newhtml = '<a rel="'+i+'" href="'+mainurl+'/gallery/findimg/imgid/'+$(this).attr("rel")+'/lang/cz"></a>'
                } else {
                    newhtml = '<a rel="'+i+'" href="'+mainurl+'/gallery/findimg/imgid/'+$(this).attr("rel")+'/lang/en"></a>'
                }

            } else {

                if(lang == "cz") {
                    newhtml = '<a rel="'+i+'" href="'+mainurl+'/cz/fotobanka/"></a>'
                } else {
                    newhtml = '<a rel="'+i+'" href="'+mainurl+'/en/photobank/"></a>'
                }


            }
            var href = $(this).attr("href");
            $(".widefoto").append(newhtml);
             $(".widefoto a[rel='"+i+"']").hide();
             $(".widefoto a[rel='"+i+"']").html('<img src="'+href+'" />')

        })
        pos = $(".homesmallphoto.active").prevAll().length;
        //alert(pos);

//        if ($.browser.msie) {
//
//            $(".homesmallphoto").boxShadow(  0,   0, 7, "#666");
//            $(".homesmallphoto.active").boxShadow(  0,   0, 10, "#00609F");
//
//        }

        $(".homesmallphoto a").click(function(){
            // active class
            $(".homesmallphoto").each(function(){
                $(this).removeClass("active");
            });
            $(this).parent().addClass("active");
//            if ($.browser.msie) {
//
//                $(".homesmallphoto").boxShadow(  0,   0, 7, "#666");
//                $(".homesmallphoto.active").boxShadow(  0,   0, 10, "#00609F");
//
//            }
            // slider
            var txt = $(this).attr("title");
            var txtArray =  txt.split(' :: ');
            //alert(txt);
            $("#homedescbox span").html(txtArray[0]);
            $("#homedescbox small").html(txtArray[1]);
            // mainphoto
pos = $(this).attr('name');
//alert(n);
            $(".widefoto a").hide();
            $(".widefoto a[rel='"+pos+"']").show();

//            if($(".widefoto a").attr("rel") == "cz") {
//                if($(this).attr("rel") !=0){
//                    $(".widefoto a").attr("href", "/capturelight.cz/gallery/findimg/imgid/"+$(this).attr("rel")+"/lang/cz") ;
//                } else {
//                    $(".widefoto a").attr("href", "/capturelight.cz/cz/fotobanka/") ;
//                }
//
//
//            } else {
//                if($(this).attr("rel") !=0){
//                    $(".widefoto a").attr("href", "/capturelight.cz/gallery/findimg/imgid/"+$(this).attr("rel")+"/lang/en") ;
//                } else {
//                    $(".widefoto a").attr("href", "/capturelight.cz/en/photobank/") ;
//                }
//
//            }
////            $(".widefoto a img").attr("src",$(this).attr("href"));

            pos--;
        
            return false;
        });
    

 


        $(".sliderbox .next").click(function(){
            if(pos+1 < $(".homesmallphoto").length) {
                pos = pos + 1;
            } else {
                pos = 0;
            }
            $(".homesmallphoto a:eq("+pos+")").click();
            return false;
        });
    

        $(".sliderbox .prev").click(function(){
            if(pos > 0) {
                pos = pos - 1;
            } else {
                pos = $(".homesmallphoto").length -1;
            }
           
            $(".homesmallphoto a:eq("+pos+")").click();


            return false;
        });


        interval = setInterval(rotateit,5000); //time in milliseconds
   $('.widefoto').hover(function() {
     clearInterval(interval);
   }, function() {
     interval = setInterval(rotateit,5000); //time in milliseconds
//rotateit();
   });






    }
  






    if (links > 0) {

      




        $(".galcontent .onepicbox a").click(function(){


           if ($(".phblock").length > 0){
               $(".phblock").show();
           }

            // active class
            $(".onepicbox a").each(function(){
                $(this).removeClass("active");
            });
            $(this).addClass("active");
            
            // slider
            var txt = $(this).attr("title");
            var txtArray =  txt.split(' :: ');
            //alert(txt);
            $("#homedescbox span").html(txtArray[0]);
            $("span.pname").html(txtArray[0]);
            $("#homedescbox small").html(txtArray[1]);
            // mainphoto

           
            $("#galbigpic .centermiddle").html("<img src='"+$(this).attr("href")+"' />");
            pos = $(this).attr("name");


            return false;
        });



        if(location.href.search(/#last/)!=-1){
 $("#galbigpic img").hide();
            $(".galcontent a:last").click();
        }

        if(location.href.search(/#posid/)!=-1){
             $("#galbigpic img").hide();
            // alert(location.href.substr(-1));
            $(".galcontent a").eq(location.href.substr(-1)).click();
        }


        pos = parseInt($(".galcontent .active").attr("name"));



        $(".sliderbox .next").click(function(){

            if(parseInt(pos,10)+1 < links +1) {
                pos = parseInt(pos,10)+1;
                
            } else {

                if($(".paginationControl a").length > 0) {
                    if($(".activepage").nextAll().length != 0) {
                        location.href = $(".activepage").next().attr("href");

                    } else {
                        location.href = $(".paginationControl a:first-child").attr("href");
                    }
                } else {
                    pos=0;
                }
               


               
            }


            $(".onepicbox a[name='"+pos+"']").click();

      




            return false;
        });


        $(".sliderbox .prev").click(function(){
            if(parseInt(pos,10)-1 > 0) {
               
               pos  = parseInt(pos,10) - 1;

            } else {

                if($(".paginationControl a").length > 0) {
                    if($(".activepage").prevAll().length != 0) {
                        location.href = $(".activepage").prev().attr("href")+ "#last";

                    } else {
                        location.href = $(".paginationControl a:last-child").attr("href")+ "#last";
                    }
                } else {
                    pos = parseInt($(".galcontent a").length,10);
                }



               
            }
            $(".onepicbox a[name='"+pos+"']").click();


            //alert( $(".activepage").next().attr("href" ));
            return false;
        });
    }


 
if ($.browser.msie) {
var ni = 0;
    $(".galcontent div a img").each(function(){
        ni++;
      // $(this).wrap("<div class='ie-shadow'></div>")
            var pos = $(this).parent().position();
    $(this).parent().after("<div class='ie-shadow' name='"+ni+"'></div>");
   $(".ie-shadow[name='"+ni+"']").width($(this).width() + 5).height($(this).height()+ 5).css("left", (pos.left)  + "px").css("top",(pos.top) + "px");

    });


var ni2 = 0;
    $(".galcontents a img").each(function(){
        ni2++;
      // $(this).wrap("<div class='ie-shadow'></div>")
            var pos = $(this).parent().position();
    $(this).parent().after("<div class='ie-shadow' name='"+ni2+"'></div>");
   $(".ie-shadow[name='"+ni2+"']").width($(this).width() + 5).height($(this).height()+ 5).css("left", (pos.left)  + "px").css("top",(pos.top) + "px");

    });


var ni3 = 0;
    $(".homesmallphoto").each(function(){
        ni3++;
      // $(this).wrap("<div class='ie-shadow'></div>")
            var pos = $(this).position();
    $(this).append("<div class='ie-shadow' name='"+ni2+"'></div>");
   $(".ie-shadow[name='"+ni3+"']").width($(this).width() + 5).height($(this).height()+ 5).css("left", (pos.left)  + "px").css("top",(pos.top) + "px");

    });

   }

               


  
});


function rotateit () {
   $(".next").click();
}