﻿

        $(function() {
            
            $("a[rel^='prettyPhoto']").prettyPhoto({animation_speed:'fast',slideshow:10000, hideflash: true});
            
            $("#MainUl li.topLi").mouseenter(function() {
                $(this).children(".r").show();
                $(this).children(".arr").show();
                $(this).children("a").css("background-image", "url(images/topMenuBack.jpg)");
                if ($(this).children(".arr").attr("class")) {
                    
                    $(".golge").hide();
                    $(".golge").fadeIn(300);
                    $(this).children(".topSubMenu").css("top", "-500px").show();
                    if(window.location.href.indexOf("default.aspx") < 0){
                    $("#Container").append("<div class='golge' style='top:105px; z-index=3 !important;'></div>");
                    $(".golge").height(parseInt($(document).height()) - 105);
                    }else{
                    $("#MiddleTop").append("<div class='golge'></div>");
                    $(".golge").height($("#MiddleTop").height());
                    }
                    $(this).children(".topSubMenu").animate({
                        opacity: 0,
                        top: '80px'
                    }, 1, function() {
                        // Animation complete.
                    });
                    $(this).children(".topSubMenu").animate({
                        opacity: 1,
                        top: '38px'
                    }, 100, function() {

                    });
                }
            })
            
            $("#MainUl li.topLi").mouseleave(function() {
                $(this).children(".r").hide();
                $(this).children(".arr").hide();
                $(this).children("a").css("background-image", "none");
                if ($(this).children(".arr").attr("class")) {

                    $(".golge").animate({
                        opacity: 0
                    }, 300, function() {
                        $(this).remove();
                    });
                    $(this).children(".topSubMenu").animate({
                        opacity: 0,
                        top: '80px'
                    }, 100, function() {
                        $(this).hide();
                    });
                }
            })

            $(".topSubMenu li:last-child").children("a").css("border-bottom", "none");
            
            
            $(".filterMenu").mouseenter(function() {
                $(this).children(".SubMenu").show();
                $(this).children(".overThis").css("color", "#333");
            })
            $(".filterMenu").mouseleave(function() {
                $(this).children(".SubMenu").hide();
                $(this).children(".overThis").css("color", "#8c8c8c");
            })
            $(".filterMenu .SubMenu").mouseenter(function() {
                $(this).prev(".overThis").css("background", "url(images/leftDownArrow.png) right 6px no-repeat");
                $(this).prev(".overThis").css("color", "#333");
            })
            $(".filterMenu .SubMenu").mouseleave(function() {
                $(this).prev(".overThis").css("background", "");
                $(this).prev(".overThis").css("color", "#8c8c8c");
            })
            
            var vid2="";
            var vid3="";
            var vid4="";
            
            $(".bigReferenceFullBox").each(function(e) {
                    var iframe= $(this).children(".vid").html();
                    eval("vid"+(e+2)+"=iframe");
                    $(this).children(".vid").html("");
                });
                
            $(".bigReferenceBox").click(function() {
                var chl = $(this).children(".rf").text();
                $(".bigReferenceFullBox").each(function() {
                    if ($(this).attr("id") != "bgb" + chl) {
                        $(this).children(".vid").html("");
                        $(this).hide();
                    }
                });

                $("#BigReferenceFull").slideDown();
                destination = $("#BigReferenceFullAnchor").offset().top-20;
                $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 500 );
                $("#bgb" + chl).children(".vid").html(eval("vid"+($(this).index()+2)));
                $("#bgb" + chl).slideDown();
                $("#BigReferenceFullClose").fadeIn();
            })
            
            
            
            $("#BigReferenceFullClose").click(function() {
                
                $(".bigReferenceFullBox").each(function() {
                    $(this).slideUp();
                    var iframe= $(this).children(".vid").html();
                    $(this).children(".vid").html("");
                    //$(this).children(".vid").html(iframe);
                });
                $("#BigReferenceFull").slideUp();
                destination = 0;
                $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 500 );
                $(this).fadeOut();
            })

            $(".referenceBox").click(function() {
                var offset = $(this).position();
                var rid = $(this).children(".rf").text();
                var index = $(this).index();
                getReferenceByReferenceId(rid,offset.top,index);
            })

            $(".referenceLigthBox #closeButton").click(function() {
                $(".transparentWhite").fadeOut("slow");
                $(".referenceLigthBox").fadeOut("slow");
//                var mainTop = $("#ReferenceBoxesContainer").offset();
//                $("html:not(:animated),body:not(:animated)").animate({ scrollTop: (mainTop.top-50)}, 500 );
            })
            
            $(".newsMenu h2").click(function() {
                $(".newsMenuContent").slideUp("fast");
                $(this).next().slideDown();
            })

            $('#showCase').cycle({
                fx: 'scrollHorz',
                speed: 'slow',
                timeout: 6000,
                delay: -2000,
                pager: '#showCaseNav',
                pagerEvent: 'click',
                pauseOnPagerHover: true,
                pause:1,
                cleartype: !$.support.opacity,
                cleartypeNoBg: true
            });

            $('#showCaseNav a').mouseenter(function() {
                $(".slidePopUp").remove();
                $(this).append("<div class='slidePopUp'><img src='" + $(".showCaseBox:eq(" + $(this).index() + ")").children(".popUp").children("img").attr("src") + "' alt='' /></div>");
                $(".slidePopUp").fadeIn("slow");
            });

            $('#showCaseNav a').mouseleave(function() {
                $(".slidePopUp").remove();
            });

            $('#ViewSliderCont').cycle({
                fx: 'fade',
                speed: 'slow',
                timeout: 9000,
                delay: -2000,
                pager: '#ViewSliderNav',
                pagerEvent: 'click',
                pauseOnPagerHover: true,
                cleartype:     !$.support.opacity,
                cleartypeNoBg: true
            });

            
            $('#BrandBox .brands').bxSlider({
            displaySlideQty: 100,
            moveSlideQty: 1,
	        auto:true,
	        controls:false,
	        speed:1300,
	        autoHover:true,
	        infiniteLoop: true,
	        onBeforeSlide: function(currentSlide, totalSlides){
            $(".bwPhoto").show();
            $(".colorPhoto").hide();
            }
          });
            
            
             $(".bwPhoto").mouseenter(function() {
                $(this).next().fadeIn("fast");
                $(this).hide();
            })
            
            $(".colorPhoto").mouseleave(function() {
                $(this).prev().fadeIn("fast");
                $(this).hide();
            })
            
            var selectedrCat=0;
            var selectedrCli=0;
            var selectedrYear=0;
            
            $(".rCat").click(function() {
                selectedrCat = $(this).attr("rel");
                $(".filterButtons a").removeClass("selected");
                if(selectedrCat==null)
                    selectedrCat=0;
                else{
                    $(".projectTitle").html($(this).html()+" <span class='allProjects'>/ "+$(".projectTitle").attr("rel2")+"</span>");
                $(this).addClass("selected");
                $(this).parents(".filterButtons").children(".overThis").addClass("selected");
                    Cufon.refresh();
                    }
                filter(selectedrCat,"ct");
            })
            
            $(".rCli").click(function() {
                selectedrCli = $(this).attr("rel");
                $(".filterButtons a").removeClass("selected");
                if(selectedrCli==null)
                    selectedrCli=0;
                else{
                    $(".projectTitle").html($(this).html()+" <span class='allProjects'>/ "+$(".projectTitle").attr("rel2")+"</span>");
                $(this).addClass("selected");
                $(this).parents(".filterButtons").children(".overThis").addClass("selected");
                    Cufon.refresh();
                    }
                filter(selectedrCli,"cl");
            })
            
            $(".rYear").click(function() {
                selectedrYear = $(this).attr("rel");
                $(".filterButtons a").removeClass("selected");
                if(selectedrYear==null)
                    selectedrYear=0;
                else{
                    $(".projectTitle").html($(this).html()+" <span class='allProjects'>/ "+$(".projectTitle").attr("rel2")+"</span>");
                    $(this).addClass("selected");
                    $(this).parents(".filterButtons").children(".overThis").addClass("selected");
                    Cufon.refresh();
                    }
                filter(selectedrYear,"yr");
            })
            
            $(".allProjects").live("click", function(){ 
                 $(".referenceBox").show("slow");
                 $(".projectTitle").html($(".projectTitle").attr("rel"));
                 pager($(".referenceBox").size());
                 $("#ReferenceBoxNav a:first").addClass("activeSlide");
                 $(".filterButtons a").removeClass("selected");
                 Cufon.refresh();
             });
             
             $("a[rel='IframeVid']").click(function(event) {
                  event.preventDefault();
                  ModalBox($(this).attr("href"));
             });
             
             $("#ModalBoxClose").live("click",function() {
                  ModalBoxClose();
             });
             
             $("#ModalBoxCont").live("click",function() {
                  ModalBoxClose();
             });
            
            var bImg = $(".backGroundImgCatch").children("img").attr("src");
            if (bImg!=null){
                $(".backGroundImgCatch").css("background-image","url("+bImg+")").html("");
            }
            pager($(".referenceBox").size());
            
            $("#ReferenceBoxNav a:first").addClass("activeSlide");
             
            $("#ReferenceBoxNav a").live("click", function(){ 
                 if($(this).attr("class")!="activeSlide"){
                     $("#ReferenceBoxNav a").removeClass("activeSlide");
                     var itemNumber = $(this).index();
                     $('#PagerDiv').animate({top:-(itemNumber*665)},600);
                     $(this).addClass("activeSlide");
                 }
             });
             

        })
        
        function pager(total){
            $("#ReferenceBoxNav a").remove();
            var page = Math.ceil(total / 12);
            for (i=1;i<=page;i++){
                $("#ReferenceBoxNav").append("<a href='' onClick='return false;'>"+i+"</a>");
            }
        }
        
        function filter(selectedVal,att){
            $(".referenceBox").each(function(){
                if(selectedVal!=0){
                    $('.referenceBox['+att+'!="'+selectedVal+'"]').hide("slow");
                    $('.referenceBox['+att+'="'+selectedVal+'"]').show("slow");
                }else{
                    $(".referenceBox").show("slow");
                    $(".projectTitle").html($(".projectTitle").attr("rel"));
                    Cufon.refresh();
                }
            });
            if(selectedVal!=0){
                pager($('.referenceBox['+att+'="'+selectedVal+'"]').size());
                }
            else{
                pager($(".referenceBox").size());
                }
            $('#PagerDiv').css("top","0");
            $("#ReferenceBoxNav a:first").addClass("activeSlide");
        }

        function txtCont(id, txt) {
            if ($("#" + id).val() == txt) {
                $("#" + id).val("");
            }
        }
        function txtCont2(id, txt) {
            if ($("#" + id).val() == "") {
                $("#" + id).val(txt);
            }
        }
        
        function mm(gelen1,gelen2){
	            document.write("<a class='DevamOk' href='ma"+"ilto:" + gelen1 + "@" + gelen2 + "."+"com"+"'>"+ gelen1 +"@"+ gelen2 +"."+"com"+"</a>")
            }
            
        function getReferenceByReferenceId(referenceId,top,indexs) {
            $.ajax({
                type: "POST",
                url: "Ajax.aspx/GetReferenceByReferenceId",
                data: "{referenceId:'" + referenceId + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(msg) {
                    
                     var catName="";
                     var btnProject="";
                    if(LanguageId==2){
                        catName=msg.d.categoryName;
                        btnProject="btnProjeyiGor.png";
                        }
                    else{
                        catName = msg.d.categoryNameEng
                        btnProject="btnProjeyiGorEn.png";
                        }
                        
                    if(msg.d.link!=""){
                    $(".referenceLigthBox").children(".right").html("<strong>" + msg.d.title + "</strong><span>" + msg.d.workDate + " - " + catName + "</span>" + msg.d.about + "<a href='" + msg.d.link + "' target='_blank'><img src='images/"+btnProject+"' class='button' /></a>");
                    }else{
                    $(".referenceLigthBox").children(".right").html("<strong>" + msg.d.title + "</strong><span>" + msg.d.workDate + " - " + catName + "</span>" + msg.d.about);
                    }

                    if (msg.d.extraImage == "0") {
                        $(".referenceLigthBox").children(".left").children(".navLeft").hide();
                        $(".referenceLigthBox").children(".left").children(".navRight").hide();
                        $(".referenceLigthBox").children(".left").children(".photos").html("<img src='"+adminPath+"MakeThumbnail.aspx?file=Upload/Images/" + msg.d.image + "&width=592&height=333' width='592' height='333' alt='' />");
                    } else {
                        var imgs = msg.d.extraImage.split(",");
                        var imgsHtml = "";
                        for (i = 0; i < imgs.length; i++) {
                            imgsHtml += "<img src='"+adminPath+"MakeThumbnail.aspx?file=Upload/Images/" + imgs[i] + "&width=592&height=333' width='592' height='333' alt='' />"
                        }
                        $(".referenceLigthBox").children(".left").children(".photos").html("<img src='"+adminPath+"MakeThumbnail.aspx?file=Upload/Images/" + msg.d.image + "&width=592&height=333' width='592' height='333' alt='' />" + imgsHtml);
                    }
                    $(".referenceLigthBox").children(".left").children(".photos").cycle({
                        fx: 'blindX',
                        speed: 'slow',
                        timeout: 3000,
                        delay: -2000,
                        next: '.navRight',
                        prev: '.navLeft'
                    });

                    $(".referenceLigthBox").children(".lbLeft").hide();
                    $(".referenceLigthBox").children(".lbRight").hide();
                    
                    $(".transparentWhite").fadeIn("slow");
                    
                    var mainTop = $("#ReferenceBoxesContainer").offset();
                    $("html:not(:animated),body:not(:animated)").animate({ scrollTop: ((mainTop.top)-50)}, 500 );
                    $(".referenceLigthBox").css("top","25px");
                    $(".referenceLigthBox").fadeIn("slow");
                },
                error: function(xhr, status, errorThrown) {
                    alert(xhr.responseText+"hata");
                }
            });
        }
        function ModalBox(v){
            var html = '<div id="ModalBoxCont"><div id="ModalBox"><div id="ModalBoxClose"></div><iframe src="video.aspx?l='+v+'" width="100%" height="100%" frameborder="0"></iframe></div></div>';
            $("body").append(html);
            $("#ModalBoxCont").css("height",$(document).height()+"px").show();
            $("#ModalBox").fadeIn("fast");
        }
        function ModalBoxClose(){
            $("#ModalBoxCont").remove();
        }
