﻿function Load() {

    InitDropDownList();
    InitMask();
    LoadFlash();
    
    $('div.tur:first').css("background-image","none");
    $(".tur").attr("rel", "0");
    
    var i = 0;
    $(".tur").each(function() {
        $(this).attr("rel", i);
        i++;
    });

    $('ul.submenu li:last-child').css("border-bottom", "none");


    var tursize = $(".turlar a").size();
    if (tursize > 5) {
        var topsize = $(".tur").size() * 174;
        var delta = 1;
        var turInterval;
        turInterval = setInterval(turIntervalFn, 5000);
        $(".ileri").click(geri);
        $(".geri").click(ileri);
        $(".turlar").mousewheel(turwheel);
        $(".turlar").hover(function() { clearInterval(turInterval); }, function() { turInterval = setInterval(turIntervalFn, 5000); });
        function turwheel(event, delta) {
            if (delta == -1) {
                ileri();
            }
            else {
                geri();
            }
            $('.turlar').unbind("mousewheel");
            setTimeout(function() { $(".turlar").mousewheel(turwheel); }, 500);
        }
        function ileri() {
            if ((((tursize * 174) - (175 * 5)) * -1) < parseInt($(".turlar").css("left").replace("px", ""))) {
                $(".turlar").animate({ "left": "-=174px" }, 500);
            }
        }
        function geri() {
            if (parseInt($(".turlar").css("left").replace("px", "")) < 0) {
                $(".turlar").animate({ "left": "+=174px" }, 500);
            }
        }
        function turIntervalFn() {
            if (parseInt($(".turlar").css("left").replace("px", "")) == 0) {
                delta = 1;
            }
            else if ((((tursize * 174) - (175 * 5)) * -1) > parseInt($(".turlar").css("left").replace("px", ""))) {
                delta = 0;
            }
            if (delta == 1) {
                ileri();
            }
            else {
                geri();
            }
        }
    }

    $("div.baslik").click(function()
        {
            var $this = $(this);
            $("div.baslik").css("background-image","url(Images/prgkapali.jpg)");
            if ( $this.parent().find("div.detay").css("display") == "none" ) {
            
                
                $("div.detay").slideUp(200);
                setTimeout(function(){
                    $this.css("background-image","url(Images/prgacik.jpg)")
                    $this.parent().find("div.detay").slideDown(300);
                },200);
            
            }
            else {
                $this.parent().find("div.detay").slideUp(300);
            }
            
        });
        
    $(".detay:eq(0)").show();
    $("div.baslik:eq(0)").css("background-image","url(Images/prgacik.jpg)");



    $("*[rel=jsabox_swf]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' src='" + $(this).attr("href") + "' width='" + $(this).attr("width") + "' height='" + $(this).attr("height") + "'></div>");
        $("#jsabox").show();
        LoadFlash();
        return false;
    });

    $("*[rel=jsabox_html]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' src='" + $(this).attr("href") + "' width='" + $(this).attr("width") + "' height='" + $(this).attr("height") + "'></div>");
        $("#jsabox").show();
        LoadFlash();
        return false;
    });

    $("*[rel=jsaBox_html]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='lightboxcontent'>" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });

    $("*[rel=jsaBox_map]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='mapcontent'>" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });

    $("*[rel=jsaBox_flash]").click(function() {
        var item = $("#" + $(this).attr("href")).clone().show();
        $("#jsaboxcontent").html("<div class='lightboxcontent' style='width:600px;height:180px;'><img src='Images/close.jpg' class='close' />" + item.html() + "</div>");
        $("#jsabox").show();
        return false;
    });

    $("#jsabox").click(function() { CloseItem(); });

    $("*[rel=jsabox_video]").click(function() {
        $("#jsaboxcontent").html("<div type='Flash' class='lightboxcontents' src='Flash/VideoPlayer.swf?pvideo=" + $(this).attr("href") + "' width='303px' height='235px'></div>");
        LoadFlash();
        $("#jsabox").show();
        return false;
    });

    $(".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 DateN() {
    $(".Datex").mask("99/99/9999").blur(function () {
        if (!DateControl($(this).val())) {
            $(this).val("");
        }
    });
}

function check() {
    $(".FormOut").css("margin-top", $("#ctl00_Main_MenuParent").height() - 60);
}

function InitMask(xx) {
    if (xx == 0) {check(); }
    
    $(".Phone").mask("999 9999999");
    $(".Date").mask("99/99/9999").blur(function () {
        if (!DateControl($(this).val())) {
            $(this).val("");
        }
    });
    $(".Number").keyup(function () {
        if (!IsNumeric($(this).val())) {
            $(this).val(ConvertNumeric($(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("");
        }
    });
}

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=true]").text() + "</span>" + $(this).html()); });
            }
        })
        $(".inputdrp").change(function () { $(this).parent().find(".inputdrpText").html($(this).find("option[selected=true]").text()); });

        $(".inputdrp_x").each(function () {
            if ($(this).attr("isdrp") != "true") {
                $(this).attr("isdrp", true);
                $(this).parent().addClass("inputdrpParent_x").each(function () { $(this).html("<span class='inputdrpText_x'>" + $(this).find("option[selected=true]").text() + "</span>" + $(this).html()); });
            }
        })
        $(".inputdrp_x").change(function () { $(this).parent().find(".inputdrpText_x").html($(this).find("option[selected=true]").text()); });

    }
}


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();
                if ($("#imgDesc").html().toString().length > 0) {
                    $("#imgDesc").show();
                }
                else {
                    $("#imgDesc").hide();
                }
            });
        });
    }).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);

        $("#imgDesc").html($this.attr("desc"));

        $("#imgdesc").hide();

        $(".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 / 6) * 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 / 4) * 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 focusText(field) {
    if (field.defaultValue == field.value) field.value = '';
}

function blurText(field) {
    if (field.value == '') { field.value = field.defaultValue; }
}

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 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 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 jsaboxcontentLoad(url,file) {
//        $("#jsaboxcontent").html("<div class='lightboxcontent'><a href='" + url + "'><img src='" + file + "' usemap='#Map' class='lightboximage' /></div>");
//        $(".lightboximage").resize({ parentElement : $('.lightboxcontent') });
//        $("#jsabox").show(); 
//    return false;
//}
       


function jsaboxcontentLoad(url, file) {
    $("#jsaboxcontent").html("<div class='lightboxcontent'><a href='" + url + "'><img src='" + file + "' class='lightboximage' /></a></div>");
    $(".lightboximage").resize({ parentElement: $('.lightboxcontent') });
    $("#jsabox").show();
     return false;
     }

     $(function () { check() });
