﻿function Load() {

    doResize(); 
    LoadFlash();
    InitDropDownList();
    InitMask();
    
	$(window).bind('resize', function() {
	        doResize();
    });
    
    $(".prohover span").mouseenter(function() {
    $(this).css("display","block").animate({top: "5px", opacity: 0.9}, { duration: 300, queue: false });
               }).mouseleave(function(){
    $(this).animate({top: "-10px", opacity: 0}, { duration: 300, queue: false });
    });
    
    $(".maincontent").each(function(){
        if ( $(".mainpic").height() >= $(this).height()  ) {
            $(this).css("height", $(".mainpic").height() - 80);
        }
    });
    
    $('ul.mainmenu li:last-child').addClass('last');

    
    $(".focusempty").each(function(){$(this).focusEmpty()});
    
    $("*[rel=jsabox_img]").click(function() {
        
        $("#jsaboxcontent").html("<div class='lightboxcontent'><img src='Images/close.jpg' class='close' /><img src='" + $(this).attr("href") + "' /></div>");
        
        $(".lightboxcontent").click(function(){return false;});
        $(".lightboxcontent .close").click(function(){CloseItem();});

        $("#jsabox").show();
        return false;
    });
    
    $("*[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_ad]").click(function() {
        $("#jsaboxcontent").html("<div id='showflash'></div>");
        $("#showflash").click(function(){ return false;}).GenerateFlash({ src: "Flash/ReklamFilmleri.swf?pvideo=" + $(this).attr("href") , width: "420px", height: "340px" }).append("<div class='closebutton'><a onclick='javascript:CloseItem();'><img src='Images/close.png' class='close' /></a></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();});
    
    

    
    
    
    $(".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 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());});
    }
}

function InitMask() {
    $(".Phone").each(function() {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).mask("9(999) 999-9999");
        }
    });
    $(".Date").each(function() {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).mask("99/99/9999");
        }
    }).blur(function() {
        if (!DateControl($(this).val())) {
            $(this).val("");
        }
    });
    $(".Year").each(function() {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).mask("9999");
        }
    });
    $(".TC").each(function() {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).mask("99999999999");
        }
    });
    $(".TaxNumber").each(function() {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).mask("9999999999");
        }
    });   
    $(".Hour").each(function() {
        if ($(this).attr("ismask") != "1") {
            $(this).attr("ismask", "1");
            $(this).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 CloseItem() {
    $("#jsaboxcontent").html("").slideUp(250);
    setTimeout(function(){ $("#jsabox").hide(); $("#jsaboxcontent").show(); },250);
}

function openImage(fileUrl) {
    $("#jsaboxcontent").hide().html("<div class='qualtycontent' id='showflash'></div>")
    $("#jsabox").show();
    $("#showflash").GenerateFlash({ src: "Flash/LightBox.swf?urlPic=" + fileUrl , width: "420px", height: "573px" });
    setTimeout(function(){
    $("#jsaboxcontent").slideDown(300);
    },200);    
}

function ShowParent($this, StopItem) {
    $this.parent().find("li").show();
    if ( $(StopItem).attr("id") != $this.attr("id") ) {
        ShowParent($this.parent(),StopItem);
    }
}

function doResize() {
    if($.browser.msie){
        $('.container').addClass('browserIE' + $.browser.version.substring(0,1));
        $('.pagecontainer').addClass('pageIE' + $.browser.version.substring(0,1));
    }
    if ( $(window).height() > 102 ) {
        $(".container").css("min-height", ($(window).height() - 102)).css("height", ($(window).height() - 102));
        $(".browserIE7").css("min-height", ($(window).height() - 530)).css("height", ($(window).height() - 530));
    	$(".pageIE7").css("min-height", ($(window).height() - 380)).css("height", ($(window).height() - 380));
	}
 
}

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 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;
}
