﻿$(document).ready(function() {













    /*Login*/
//    $(".btnLogin").click(function() {
//        $(".loginProcessBox").fadeIn("slow");
//        return false;
//    });

//    $(".btnEnter").click(function() {
//        $(".close").fadeOut("slow");
//        $(".loginError").fadeIn("slow");
//        return false;
//    });

//    $(".btnSend").click(function() {
//        $(".close").fadeOut("slow");
//        $(".loginRememberOk").fadeIn("slow");
//        return false;
//    });

//    $(".btnRemember").click(function() {
//        $(".close").fadeOut("slow");
//        $(".loginRemember").fadeIn("slow");
//        return false;
//    });

//    $(".LoginClose").click(function() {
//        $(".close").fadeOut("slow");
//        return false;
//    });

//    $(".btnSaveFrm").click(function() {
//        $(".loginFormError").fadeIn("slow");
//        return false;
//    });

function addLoginOverlay() {
    $("body").append('<div class="login-overlay"></div>');
    $(".login-overlay").css({ opacity: 0.7 });
}

function removeLoginOverlay() {
    $(".login-overlay").remove();
}


    $('.memberNewFirm input[type=text]').attr("disabled", "disabled").css("background", "#e87e8a").css("color", "#f1f1f1");
    $(".chkCompany").click(function() {
        if ($('.chkCompany').attr('checked')) {
            $('.memberNewFirm input[type=text]').removeAttr("disabled").css("background", "white").css("color", "black");
        } else {
            $('.memberNewFirm input[type=text]').attr("disabled", "disabled").css("background", "#e87e8a").css("color", "#f1f1f1");
        }
    });

    $('.memberNewFirm select').attr("disabled", "disabled").css("background", "#e87e8a").css("color", "#f1f1f1");
    $(".chkCompany").click(function() {
        if ($('.chkCompany').attr('checked')) {
            $('.memberNewFirm select').removeAttr("disabled").css("background", "white").css("color", "black");
        } else {
        $('.memberNewFirm select').attr("disabled", "disabled").css("background", "#e87e8a").css("color", "#f1f1f1");
        }
    });

    $('.memberNewFirm textarea').attr("disabled", "disabled").css("background", "#e87e8a").css("color", "#f1f1f1");
    $(".chkCompany").click(function() {
        if ($('.chkCompany').attr('checked')) {
            $('.memberNewFirm textarea').removeAttr("disabled").css("background", "white").css("color", "black");
        } else {
        $('.memberNewFirm textarea').attr("disabled", "disabled").css("background", "#e87e8a").css("color", "#f1f1f1");
        }
    });

    if ($('.viewport').html() == null) {
    }
    else {
        $('.applicationBoxList=>li').each(function(index) {


            var liLength = $(this).find(".toggleHover li").length;
            if (liLength > 2) {
                $(this).find('.viewport').carousel('.simplePrevious', '.simpleNext');
            }
            else { }

            $(this).find('.viewport').hide();

            $(this).hover(
              function() {
                  $(this).find('.toggleText').hide();
                  $(this).find('.viewport').show();
              },
              function() {
                  $(this).find('.viewport').hide();
                  $(this).find('.toggleText').show();
              }
            );
        });
    }

    $('.topMenu a:last-child, .loginBox a:last-child').css("border", "none").css("paddingRight", "0");

    $('.imgSlider').each(function() {
        $(this).before('<div class="imgSliderNav"></div>')
        .cycle({
            speed: '750',
            timeout: 4000,
            pause: true,
            pager: $(this).prev()
        });
    });

    function mycarousel_initCallback(carousel) {
        carousel.buttonNext.bind('click', function() {
            carousel.startAuto(0);
        });

        carousel.buttonPrev.bind('click', function() {
            carousel.startAuto(0);
        });

        carousel.clip.hover(function() {
            carousel.stopAuto();
        }, function() {
            carousel.startAuto();
        });

        jQuery('.tweetBtnNext').bind('mouseover', function() {
            carousel.next();
            return false;
        });

        jQuery('.tweetBtnPrev').bind('mouseover', function() {
            carousel.prev();
            return false;
        });
    };
    if ($('.ticker').html() == null | $('.ticker li').length < 3) {
    }
    else {
        $('.ticker').jcarousel({
            vertical: true,
            //wrap: 'circular',
            scroll: 1,
            auto: 2,
            wrap: 'last',
            animation: 700,
            initCallback: mycarousel_initCallback
        });
    }

    if ($('.tickernews').html() == null ) {
    }
    else {
        $('.tickernews').jcarousel({
            vertical: true,
            //wrap: 'circular',
            scroll: 1,
            auto: 2,
            wrap: 'last',
            animation: 700,
            initCallback: mycarousel_initCallback
        });
    }

    /*Default Page*/
    $(window).resize(function () {
        calculateWindowSize();
    });
//    $('.applicationBoxRContent').hide();
    $('.applicationBoxResult').click(function () {
        $(".tab_content").hide();
        $('.applicationBoxRContent').slideToggle('slow', function (obj) {
            $('html, body').animate({ scrollTop: parseInt($(".tab_container").offset().top) }, 'slow', function () {
                calculateWindowSize();
            });
            if ($(this).css("display") == "block") {
                $('#btnOpenCloseControl').text("KAPATMAK");
            }
            else {
                $('#btnOpenCloseControl').text("AÇMAK");
            }
        });
    });

    $(".tab_content").hide();
    $(".applicationBoxListContainer li").click(function () {
        $(".applicationBoxListContainer li").removeClass("active");
        $(this).addClass("active");
        $(".tab_content").hide();

              if ($(this).find("a").attr("href").indexOf("#") == -1) {
               $('a[target="_blank"]').click(function() {
                 window.open($(this).attr('href'));
                  return false;
                });

              } else {
              var activeTab = $(this).find("a").attr("href");
              $(activeTab).slideToggle();
              $('html, body').animate({ scrollTop: parseInt($(".tab_container").offset().top) }, 'slow', function() {
                  calculateWindowSize();



              });
              return false;
              }
        
       
    });

    calculateWindowSize();

    function calculateWindowSize() {
        var windowHeight = $(window).height();
        var containerHeight = $(".container").height();
        if (containerHeight + 120 > windowHeight) {
            $(".down-arrow").remove();
            $(".container").prepend('<div class="down-arrow"></div>');
        }
        else {
            $(".down-arrow").remove();
        }
    }

    $(window).scroll(function() {
        if ($(window).height() + $(window).scrollTop() == $(document).height()) {
            $(".down-arrow").remove();
        }

        if ($(window).scrollTop() == 0 || containerHeight + 120 > windowHeight) {
            $(".container").prepend('<div class="down-arrow"></div>');
        }
    });




    lightBoxResize();

    $(window).resize(function () {
        lightBoxResize();
    });

    function lightBoxResize() {
        var windowWidth = $(window).width();
        var windowHeight = $(window).height();
        var calWindowWidth = (windowWidth - $("#facybox").width()) / 2;
        if (parseInt(calWindowWidth) > 0) {
            $("#facybox").css("left", parseInt(calWindowWidth));
        }
        else {
            $("#facybox").css("left", "0");
        }


    }

    $('a[rel*=facybox]').facybox({});
	
});


////
////






/*Img Thumb Slider*/

jQuery.fn.carousel = function(previous, next, options) {
    var sliderList = jQuery(this).children()[0];

    if (sliderList) {
        var increment = jQuery(sliderList).children().outerWidth("true"),
		elmnts = jQuery(sliderList).children(),
		numElmts = elmnts.length,
		sizeFirstElmnt = increment,
		shownInViewport = Math.round(jQuery(this).width() / sizeFirstElmnt),
		firstElementOnViewPort = 1,
		isAnimating = false;

        for (i = 0; i < shownInViewport; i++) {
            jQuery(sliderList).css('width', (numElmts + shownInViewport) * increment + increment + "px");
            jQuery(sliderList).append(jQuery(elmnts[i]).clone());
        }

        jQuery(previous).click(function(event) {
            if (!isAnimating) {
                if (firstElementOnViewPort == 1) {
                    jQuery(sliderList).css('left', "-" + numElmts * sizeFirstElmnt + "px");
                    firstElementOnViewPort = numElmts;
                }
                else {
                    firstElementOnViewPort--;
                }

                jQuery(sliderList).animate({
                    left: "+=" + increment,
                    y: 0,
                    queue: true
                }, "swing", function() { isAnimating = false; });
                isAnimating = true;
            }
            return false;
        });

        jQuery(next).click(function(event) {
            if (!isAnimating) {
                if (firstElementOnViewPort > numElmts) {
                    firstElementOnViewPort = 2;
                    jQuery(sliderList).css('left', "0px");
                }
                else {
                    firstElementOnViewPort++;
                }
                jQuery(sliderList).animate({
                    left: "-=" + increment,
                    y: 0,
                    queue: true
                }, "swing", function() { isAnimating = false; });
                isAnimating = true;
            }
            return false;
        });
    }
};

