// DOM Ready
jQuery(function($) {
    //    var pg = location.href.split('#');
    //    if (pg.length > 1 && pg[1].indexOf('/') != -1)





    $page1 = $("#page1").css({ display: 'block', visibility: 'hidden', top: -1400 });
    $page2 = $("#page2").css({ display: 'block', visibility: 'hidden', top: -1400 });
    $page3 = $("#page3").css({ display: 'block', visibility: 'hidden', top: -200 });
    $page4 = $("#page4").css({ display: 'block', visibility: 'hidden' }); // kayma problemi yuzunden display: 'block' kaldırıldı
    $page5 = $("#page5").css({ display: 'block', visibility: 'hidden', top: -1300 });
    $page6 = $("#page6").css({ display: 'block', visibility: 'hidden', top: -1400 });



    String.prototype.trim = function() {
        return this.replace(/^\s+|\s+$/g, "");
    };




    /*Tiga hakkına*/
    $('#coda-slider-1').codaSlider({
        autoSlide: false,
        //slideEaseFunction: "easeOutBounce",
        slideEaseDuration: 1300,
        autoSlideStopWhenClicked: true,
        dynamicArrows: false,
        dynamicTabs: false

    });

    $('a.lnkTigaHakkinda').click(function(e) {
        $.History.setHash($(this).attr('href'));
        return false;
    });


    /*Scrollbars*/
    $('#hizmetlerimizPanel').jScrollPane({ showArrows: true, scrollbarWidth: 29, dragMinHeight: 22, dragMaxHeight: 22 });


    createPortfolioMenu();



    //iletişim

    $("div.contactForm").animate({ height: '0px', opacity: 0 });

    setContactValidate("commentForm1");
    setContactValidate("commentForm2");


    $("a.contactToggle").click(function(e) {
        e.preventDefault();
        var div = this.href.split('#')[1];

        if ($("#" + div).get(0).style.height != '0px') {//açık olan linke tıklanırsa sadece kendini kapatır

            $("#" + div).animate({ height: '0px', opacity: 0 }, 'slow');

        }
        else {//kapalı olan linke tıklanırsa kendini açar diğerini kapatır

            $("#" + div).animate({ height: '450px', opacity: 1.0 });
            div = div == 'contactGeneral' ? 'contactBussiness' : 'contactGeneral';
            $("#" + div).animate({ height: '0px', opacity: 0 }, 'slow');

        }
    });




    $.History.bind(function(fragment) {

        var tigaPages = new Array();
        tigaPages['tiga-hakkinda'] = 1;
        tigaPages['hizmetler'] = 2;
        tigaPages['biz-kimiz'] = 3;
        tigaPages['neler-yaptik'] = 4;
        tigaPages['blog'] = 5;
        tigaPages['iletisim'] = 6;

        if (fragment.charAt(0) == '!')
            fragment = fragment.substr(1, fragment.length - 1);

        var page = fragment.split('/');
        if (page.length > 1) {
            var p = tigaPages[page[1]];
            $('#initialTigaLogo').remove();
            if (p > 0)
                Tiga.PageController.changePage(p);
            if (page.length > 2)
                changeInnerPage(page[1], page[2]);
            else
                changeInnerPage(page[1], null);
        }
    })




});




function changeInnerPage(page, innerPage) {
    switch (page) {

        case 'tiga-hakkinda':
            if (isEmpty(innerPage))
                $('#lnkhakkimizda').click();
            else
                $('#lnk' + innerPage).click();
            break;

    }
};

function isEmpty(obj) {
    return ((obj == null) || (obj == 'undefined') || (obj == ''));
};

function createPortfolioMenu() {

    //Background color, mouseover and mouseout
    var colorOver = '#AD53FF';
    var colorOut = '#1f1f1f';

    //Padding, mouseover
    var padLeft = '20px';
    var padRight = '20px';

    //Default Padding
    var defpadLeft = $('#menu li a').css('paddingLeft');
    var defpadRight = $('#menu li a').css('paddingRight');

    //Animate the LI on mouse over, mouse out
    $('#menu li').mouseover(function() {

        //mouse over LI and look for A element for transition
        $(this).find('a')
		.animate({ paddingLeft: padLeft, paddingRight: padRight }, { queue: false, duration: 100 })
		.animate({ backgroundColor: colorOver }, { queue: false, duration: 200 });

    }).mouseout(function() {

        //mouse oout LI and look for A element and discard the mouse over transition
        $(this).find('a')
		.animate({ paddingLeft: defpadLeft, paddingRight: defpadRight }, { queue: false, duration: 100 })
		.animate({ backgroundColor: colorOut }, { queue: false, duration: 200 });
    });

    //Scroll the menu on mouse move above the #sidebar layer
    $('#sidebar').mousemove(function(e) {

        //Sidebar Offset, Top value
        var s_top = parseInt($('#sidebar').offset().top) + 15;

        //Sidebar Offset, Bottom value
        var s_bottom = parseInt($('#sidebar').height() + s_top);

        //Roughly calculate the height of the menu by multiply height of a single LI with the total of LIs
        var mheight = parseInt($('#menu li').height() * $('#menu li').length);


        //Calculate the top value
        //This equation is not the perfect, but it 's very close	
        var top_value = Math.round(((s_top - e.pageY) / 100) * mheight / 3.7);

        //Animate the #menu by chaging the top value
        $('#menu').animate({ top: top_value }, { queue: false, duration: 500 });
    });

}

function initHSWhoWeAre() {

    hs.overlays.length = [];
    hs.align = 'auto';
    hs.transitions = ['expand', 'crossfade'];
    hs.outlineType = 'rounded-white';
    hs.fadeInOut = true;

    hs.dimmingOpacity = 0.55;
    /*hs.Expander.prototype.onImageClick = function(sender) { return false; }

    
    // close on mouse out
    hs.Expander.prototype.onMouseOut = function(sender) {
    sender.close();
    };
    // close if mouse is not over on expand (using the internal mouseIsOver property)
    hs.Expander.prototype.onAfterExpand = function(sender) {
    if (!sender.mouseIsOver) sender.close();
    };*/
}
function initHSPortfolio() {

    hs.align = 'center';
    hs.transitions = ['expand', 'crossfade'];
    //hs.outlineType = 'outer-glow';
    hs.outlineType = 'rounded-white';
    hs.fadeInOut = true;


    //hs.flushImgSize = true;

    hs.registerOverlay({
        html: '<div class="closebutton" onclick="return hs.close(this)" title="Kapat"></div>',
        position: 'top right',
        useOnHtml: true,
        fade: 2
    });

    //clear
    //    hs.Expander.prototype.onImageClick = null;
    //    hs.Expander.prototype.onMouseOut = null;
    //    hs.Expander.prototype.onAfterExpand = null;

    createPortfolioGalerry('genel');

}


function createPortfolioGalerry(work) {
    distroyPortfolioGalerry();
    var flashvars = {};
    flashvars.settingsXML = "include/images/portfolio/settings.xml"; //?y=" + Math.random ;
    flashvars.imagesXML = "include/images/portfolio/" + work + "/images.xml";
    flashvars.spacing = "5";
    flashvars.smoothScrolling = "true";
    flashvars.expandingDirection = "center";

    flashvars.dockWidth = "700";
    flashvars.dockHeight = "330";
    flashvars.autoScrollSpeed = "5";
    flashvars.minThumbWidth = "150";
    flashvars.minThumbHeight = "150";
    flashvars.maxThumbWidth = "280";
    flashvars.maxThumbHeight = "280";
    // flashvars.imagesInfluence = "1500";
    flashvars.fontSize = "14";
    var params = {};
    params.scale = "noscale";
    params.salign = "tl";
    params.wmode = "transparent";
    var attributes = {};
    swfobject.embedSWF("include/images/portfolio/galerry.swf", "dvPortfolioGalerry", "700", "330", "9.0.0", false, flashvars, params, attributes);
    return false;
}
function distroyPortfolioGalerry() {
    $('#portfolioContent').html('<div id="dvPortfolioGalerry"></div><div id="dvBtnPorfolioImage" style="visibility:hidden;position:absolute"></div>');
}


function openImage(path) {
    try {

        var dvBtn = document.getElementById('dvBtnPorfolioImage');

        dvBtn.innerHTML = '<input id="btnPorfolioImage" type="button" onclick=" hs.expand(null,{src: \'' + path + '\'})" value="" />';
        var btn = document.getElementById('btnPorfolioImage');
        btn.click();

    }
    catch (e) { }


}

function setContactValidate(frm) {
    $("#" + frm).validate({
        submitHandler: function(form) {

            var queryString = $("#" + frm).formSerialize();
            closeContactForm(frm);

            // the data could now be submitted using $.get, $.post, $.ajax, etc
            $.post('pages/Process.aspx', 'action=contact&' + queryString, function(data) {
                $().message(data);
            });
        }
    })
}

function closeContactForm(frm) {
    $("#lnk" + frm).click();
    $("#" + frm).resetForm();

}

window.onerror = function(msg, eUrl, eLine) {
    $.post('pages/Process.aspx', { action: 'JSError', systemMessage: msg, url: eUrl, line: eLine, browser: navigator.userAgent });
}
