/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

$(document).ready(function(){
    var loadTime = 200;

        /* TOOLTIPS */
        $("a.proLoad").easyTooltip({
              yOffset:70
        });
        
        $("#projLoadCont").ajaxStop(function(request, settings){
            $("#loadCont").hide();
         });

         $("#projLoadCont").ajaxStart(function(request, settings){
            $("#loadCont").show();
         });
         $("#projLoadCont").ajaxError(function(){
             alert("");
         });

        $.preload('.imgSet img',{
            onFinish:function(){
                $(".imgSet").each(function(i){
                    $(this).animate({opacity:1.0},200+(i*loadTime),function(){$(this).fadeIn("slow")});
                });
            }
            } 
        );

        setTimeout("showN()",4000);

        
        $(".proLoad").hover(function(){
            $(this).find("img").animate({width:"42px",height:"46px",padding:"4px"},100);
        }, function(){
            $(this).find("img").animate({width:"50px",height:"54px",padding:"0"},100);
        });


        $("#number").text($(".imgCont").length);

        /* Ajax Loading */
        $(".proLoad").click(function(){
             if(!$(this).hasClass("open")){
                $(".proLoad").removeClass("open");
                $("#projLoadCont").hide();
                $("#projectLoad, .de").show();
                $("#numberSel").text($(".proLoad").index(this)+1);
                $(".imgCont").css("backgroundColor", "#FFF")
                $(this).parent().css("backgroundColor", "#dedede")
                var p = $(this).attr("href");

                $.ajax({
                   type: "GET",
                   url: p,
                   data: "ajax=1",
                   async:true,
                   success: function(html){
                        $("#projLoadCont").html(html);
                        $.preload('#projLoadCont img',{
                            onFinish:function(){
                                $("#projectLoad").hide();
                                $("#projLoadCont").fadeIn("slow");
                                $("#contentSetUp").animate({left:"0"},1000);
                            }
                            }
                        );
                      

                   }

                 });
                $(this).addClass("open");
            }
            return false;
        });   

        $("#butHide").click(function(){
            $("#contentSetUp").animate({left:"782px",opacity:0},500).animate({opacity:1},0);
            $(".proLoad").removeClass("open");
        });

        $(".proNavLeft").click(function(){
            var margin = $("#imgSetWrap").css("marginLeft");
            margin = parseInt(margin) + 72;
            if(margin <= 0){
                $("#imgSetWrap").css("marginLeft",margin+"px");
                $(".proNavRight img").show();
                if(margin == 0){
                    $(".proNavLeft img").hide();
                }
            }
        });
        $(".proNavRight").click(function(){
            var imgCount = $(".imgSet").size();
            var maxLeft = 648 - imgCount*72;
            var margin = $("#imgSetWrap").css("marginLeft");
            margin = parseInt(margin) - 72;
            if(margin >= maxLeft){
                $("#imgSetWrap").css("marginLeft",margin+"px");
                $(".proNavLeft img").show();
                if(margin == maxLeft){
                    $(".proNavRight img").hide();
                }
            }
        });
        $("#contDownload .buttonWrap").hover(function(){
                $(this).animate({"opacity":"0.6"},200);
        },function(){
                $(this).animate({"opacity":"1.0"},200);
        });
});
function showN(){
        $(".proNavRight img").show();
}
