﻿/// <reference path="jquery-1.3.2-vsdoc2.js" />
function Load() {

    LoadFlash();
    InitDropDownList();
    InitMask();
    InitFocusEmpty();

    $("#accordion").accordion({ autoHeight: false, collapsible: true });

    $("*[rel=jsaBox_flash]").click(function () {
        $("#jsa1 .JsaBoxItemContent").html("<div type='Flash' src='Flash/VideoPlayer.swf?pvideo=" + $(this).attr("href") + "' width='300px' height='250px'></div>")
        LoadFlash();
        $("#jsa1").show();
        return false;
    });
    $("#jsa1 .JsaBoxOut").click(function () { $("#jsa1").hide(); $("#jsa1 .JsaBoxItemContent").html(""); })

    $("#jsa2 .JsaBoxOut, #jsa2 .JsaClose").click(function () { $("#jsa2").hide(); })

    $("*[rel=jsaBox_flashx]").click(function () {
        $("#jsa2 .JsaBoxItemContent").html($(this).next("div").html())
        $("#jsa2").show();
        return false;
    });

    $(".container .header .menu .item").each(function(){
        var image = $(this).attr("image");
        $(this).css("background-image","url('" + image + "')");
    });

    $(".container .header .menu .item a").hover(function(){
        $(this).parent().css("background-position","left -53px");
    }, function() {
        $(this).parent().css("background-position", "left top");        
    });
    
    $(".container .main .mainmiddle .left .bottom .item").each(function(i){
        var image = $(this).attr("image");
        i == 3 ? $(this).css("width", "168px") : "";
        $(this).css("background-image","url('" + image + "')");
    });
    $(".container .main .mainmiddle .left .bottom .item a").hover(function(){
        $(this).parent().css("background-position","left -82px");   
    },function(){
        $(this).parent().css("background-position","left top");
    });
    
    $(".container .main .mainform .mainformitems .item").each(function(){
        var image = $(this).attr("image");
        $(this).css("background-image","url('" + image + "')");
    });
    $(".container .main .mainform .mainformitems .item a").hover(function() {
        $(this).parent().css("background-position", "-97px top"); 
    },function(){
        $(this).parent().css("background-position", "left top");
    });

    $(".container .main .mainright .mainrightmenu .item").each(function () {
        var image = $(this).attr("image");
        $(this).css("background-image", "url('" + image + "')");
    });
    $(".container .main .mainright .mainrightmenu .item a").hover(function() {
        $(this).parent().css("background-position", "-109px top");
    }, function() {
        $(this).parent().css("background-position", "-12px top");
    });
    
    $(".FakeUpload").change(function(){
        $(this).parent().find(".fakeupload").val($(this).val());
    });
    
    $(".inputtext").focus(function() { $(this).css("background-position", "left bottom"); }).blur(function() { $(this).css("background-position", ""); });
    $(".inputtextarea").focus(function() { $(this).css("background-position", "left bottom"); }).blur(function() { $(this).css("background-position", ""); });
    $(".inputdrp").focus(function() { $(this).parent().css("background-position", "left bottom"); }).blur(function() { $(this).parent().css("background-position", ""); });

}

function mycarousel_initCallback(carousel) {
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function () {
        carousel.startAuto();
    });

    carousel.buttonPrev.bind('click', function () {
        carousel.startAuto();
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function () {
        carousel.stopAuto();
    }, function () {
        carousel.startAuto();
    });
};


jQuery(document).ready(function () {
    $('#mycarousel').jcarousel({
        wrap: 'last',
        initCallback: mycarousel_initCallback,
        itemLoadCallback: {
            onBeforeAnimation: mycarousel_fadeOut,
            onAfterAnimation: mycarousel_fadeIn
        }
    });
    function mycarousel_fadeOut(carousel) {
        var JCcontainerID = carousel.clip.context.id;
        $('#' + JCcontainerID).hide(0);
    }

    function mycarousel_fadeIn(carousel) {
        var JCcontainerID = carousel.clip.context.id;
        $('#' + JCcontainerID).fadeIn(300);
    }
});

function InitMask() {
    $(".Phone").mask("9(999) 999-9999");
    $(".Date").mask("99/99/9999").blur(function() {
        if (!DateControl($(this).val())) {
            $(this).val("");
        }
    });
    $(".Year").mask("9999");
    $(".TC").mask("99999999999");
    $(".TaxNumber").mask("9999999999");
    $(".Hour").mask("99:99").blur(function() {
        if (parseInt($(this).val().replace(":", "")) > 2359) {
            $(this).val("");
        }
    });

    $(".Number").keyup(function() {
        if (!IsNumeric($(this).val())) {
            $(this).val(ConvertNumeric($(this).val()));
        }
    });
    
}

function InitDropDownList() {

    var Browser = $.browser;
    if (!(Browser.msie && Browser.version == "6.0")) {
        $(".inputdrp").each(function () {
            if ($(this).attr("isdrp") != "true") {
                $(this).attr("isdrp", true);
                $(this).parent().addClass("inputdrpParent").each(function () { $(this).html("<span class='inputdrpText'>" + $(this).find("option:selected").text() + "</span>" + $(this).html()); });
            }
        })
        $(".inputdrp").change(function() { $(this).parent().find(".inputdrpText").html($(this).find("option:selected").text()); });
    }

}

function InitFocusEmpty() {
    $(".focusempty").each(function() { $(this).focusEmpty(); });
}


function InitPhotoGallery() {


    var gallerysize = $(".imagegallery .imageitems .imageitem").size();
    var galleryNumber = 0;

    $(".gallerynext").click(gallerynext);
    $(".galleryprevious").click(galleryprevious);
    $(".imagenext").click(imagenext);
    $(".imageprevious").click(imageprevious);


    $(".imagegallery .imageitems .imageitem a").each(function() {
        $(this).attr("number", galleryNumber);
        galleryNumber++;
    });

    $(".imagegallery .imageitems .imageitem a").click(function() {
        showgalleryimage($(this).attr("number"));
        return false;
    });

    $("#imgNow").load(function() {
        $(".imageloading").animate({ height: $("#imgNow").height() }, 300, function() {
            $(".imagenavigation").css("height", $("#imgNow").height());
            $(".imageloading").fadeOut(100, function() {
                $("#imgNow").show();
            });
        });
    }).hover(function() {
        $(".imagegallery .imagenavigation").show();
    });
    $(".imagegallery .imagenavigation").hover(function() {
    }, function() {
        $(".imagegallery .imagenavigation").hide();
    });

    function showgalleryimage(Number) {
        var $this = $(".imagegallery .imageitems .imageitem a:eq(" + Number + ")");
        $(".imageloading").show();

        $("#imgNow").hide().attr("src", $this.attr("binaryUrl")).attr("number", Number);
        $(".galleryinfo").html("Resim " + (parseInt(Number) + 1) + "/" + (gallerysize));
        $(".imagegallery .imageitems .imageitem a").find("img").removeClass("select");
        $this.find("img").addClass("select");
        $(".imagegallery .imageitems").animate({ top: "-" + ((Math.floor(Number / 7) * 83) + "px") }, 500);
    }

    function imagenext() {
        var Number = parseInt($("#imgNow").attr("number"));
        if (Number < gallerysize - 1) { Number++; }
        else { Number = 0; }
        showgalleryimage(Number);
    }

    function imageprevious() {
        var Number = parseInt($("#imgNow").attr("number"));
        if (Number > 0) { Number--; }
        else { Number = gallerysize - 1; }
        showgalleryimage(Number);
    }

    function gallerynext() {
        var top = parseInt($(".imagegallery .imageitems").css("top").replace("px", ""));

        if (top > (((gallerysize / 7) * 83) - 83) * -1) {
            $(".imagegallery .images .imageitems").animate({ top: "-=83px" }, 500);
        }
    }
    function galleryprevious() {
        if (parseInt($(".imagegallery .imageitems").css("top").replace("px", "")) < 0) {
            $(".imagegallery .images .imageitems").animate({ top: "+=83px" }, 500);
        }
    }

    showgalleryimage(0);

}


function CloseItem() {
    $("#jsaboxcontent").slideUp(250);
    setTimeout(function() { $("#jsabox").hide(); $("#jsaboxcontent").show(); }, 250);

}


function EmailControl(elem) {
    var str = elem;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) { return false; }
    else { return true; }
}
function IsNumeric(Text) {
    var ValidChars = "0123456789.";
    var IsNumber = true;
    var Char;
    for (i = 0; i < Text.length && IsNumber == true; i++) {
        Char = Text.charAt(i);
        if (ValidChars.indexOf(Char) == -1) { IsNumber = false; };
    }
    return IsNumber;
}
function DateControl(fld) {
    var RegExPattern = /^((((0?[1-9]|[12]\d|3[01])[\.\-\/](0?[13578]|1[02])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|[12]\d|30)[\.\-\/](0?[13456789]|1[012])[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|((0?[1-9]|1\d|2[0-8])[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?\d{2}))|(29[\.\-\/]0?2[\.\-\/]((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00)))|(((0[1-9]|[12]\d|3[01])(0[13578]|1[02])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|[12]\d|30)(0[13456789]|1[012])((1[6-9]|[2-9]\d)?\d{2}))|((0[1-9]|1\d|2[0-8])02((1[6-9]|[2-9]\d)?\d{2}))|(2902((1[6-9]|[2-9]\d)?(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00)|00))))$/;
    if ((fld.match(RegExPattern)) && (fld != '')) { return true; }
    else { return false; }
}


function ConvertNumeric(Text) {
    var ValidChars = "0123456789.";
    var Char = "";

    for (i = 0; i < Text.length; i++) {
        if (ValidChars.indexOf(Text.charAt(i)) != -1) {
            Char = Char + Text.charAt(i);
        }
    }
    return Char;
}



function CampaignLoad(url,file) {
    $("#jsaboxcontent").html("<div class='lightboxcontent'><img class='lightboxclose' src='Images/kapat.jpg' /><a href='" + url + "'><img src='" + file + "' /></a></div>");
    $("#jsabox").show();
    return false;
}

