//Cufon font replacement
Cufon.replace('h2', { fontFamily: 'Diavlo Medium' });
Cufon.replace('h3', { fontFamily: 'Diavlo Medium' });
Cufon.replace('h4', { fontFamily: 'Diavlo Medium' });
Cufon.replace('h5', { fontFamily: 'Diavlo Medium' });
Cufon.replace('h6', { fontFamily: 'Diavlo Medium' });
Cufon.replace('.slide_title', { fontFamily: 'Diavlo Medium' });
Cufon.replace('.content_slide_title', { fontFamily: 'Diavlo Medium' });
Cufon.replace('h1', { fontFamily: 'Diavlo Book' });


//Dropdown menu settings
$(document).ready(function () {
    ddsmoothmenu.init({
        mainmenuid: "menu", //menu DIV id
        orientation: 'h', //Horizontal or vertical menu: Set to "h" or "v"
        classname: 'dd', //class added to menu's outer DIV
        //customtheme: ["#1c5a80", "#18374a"],
        contentsource: "markup" //"markup" or ["container_id", "path_to_menu_file"]
    })
});

$.fn.equalHeights = function (px) {
    $(this).each(function () {
        var currentTallest = 0;
        $(this).children().each(function (i) {
            if ($(this).height() > currentTallest) { currentTallest = $(this).height(); }
        });
        if (!px || !Number.prototype.pxToEm) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
        // for ie6, set height since min-height isn't supported
        if ($.browser.msie && $.browser.version == 6.0) { $(this).children().css({ 'height': currentTallest }); }
        $(this).children().css({ 'min-height': currentTallest });
    });
    return this;
};

Number.prototype.pxToEm = String.prototype.pxToEm = function (settings) {
    //set defaults
    settings = jQuery.extend({
        scope: 'body',
        reverse: false
    }, settings);

    var pxVal = (this == '') ? 0 : parseFloat(this);
    var scopeVal;
    var getWindowWidth = function () {
        var de = document.documentElement;
        return self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
    };

    /* When a percentage-based font-size is set on the body, IE returns that percent of the window width as the font-size. 
    For example, if the body font-size is 62.5% and the window width is 1000px, IE will return 625px as the font-size. 	
    When this happens, we calculate the correct body font-size (%) and multiply it by 16 (the standard browser font size) 
    to get an accurate em value. */

    if (settings.scope == 'body' && $.browser.msie && (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(1) > 0.0) {
        var calcFontSize = function () {
            return (parseFloat($('body').css('font-size')) / getWindowWidth()).toFixed(3) * 16;
        };
        scopeVal = calcFontSize();
    }
    else { scopeVal = parseFloat(jQuery(settings.scope).css("font-size")); };

    var result = (settings.reverse == true) ? (pxVal * scopeVal).toFixed(2) + 'px' : (pxVal / scopeVal).toFixed(2) + 'em';
    return result;
};


//Latest projects slider settings
$(document).ready(function () {
    $('#projects').bxSlider({
        speed: 8000,
        displaySlideQty: 2, // How many pictures to show
        moveSlideQty: 1, // how many pictures to move in 1 slide
        auto: true
    });
});

$(document).ready(function () {

    $("#slideshow").bxSlider({
        auto: true,
        controls: false,
        mode: 'fade'
    });
    /*
    $("#duyuru_slider").bxSlider({
    auto: true,
    autoStart: true,
    controls: false,
    mode: 'vertical'
    });*/

});

var queue = 0;
var count;
var theInvertal;
var direction = "right";
var baslangic = true;

jQuery(document).ready(function () {
    jQuery("#duyuru_slider div .con").eq(0).css("top", "7px").addClass("active_s");

    jQuery("#left").click(function () {
        try {
            clearInterval(theInvertal);
            direction = "left";
            var sira;
            var item;
            var l = jQuery("#duyuru_slider div .con").size();
            for (var i = 0; i < l; i++) {
                if (jQuery("#duyuru_slider div .con").eq(i).hasClass("active_s")) {
                    sira = i;
                }
            }

            if (sira == 0)
                item = count - 1;
            else
                item = sira - 1;

            jQuery("#duyuru_slider div .con").removeClass("active_s");

            jQuery("#duyuru_slider div .con").eq(sira).animate({ top: 290 }, "slow")
            jQuery("#duyuru_slider div .con").eq(item).css("top", "-290px").animate({ top: "7px" }, "slow").addClass("active_s");

            if ((count - 1) == item)
                queue = 0;
            else
                queue = item + 1;

            if (baslangic)
                baslangic = false;

            theInvertal = setInterval(Kaydir("duyuru_slider"), 100);
        }
        catch (err) {
        }
    });

    jQuery("#right").click(function () {
        try {
            clearInterval(theInvertal);
            direction = "right";
            var sira;
            var item;
            var l = jQuery("#duyuru_slider div .con").size();
            for (var i = 0; i < l; i++) {
                if (jQuery("#duyuru_slider div .con").eq(i).hasClass("active_s")) {
                    sira = i;
                }
            }

            if (sira == (count - 1))
                item = 0;
            else
                item = sira + 1;

            jQuery("#duyuru_slider div .con").removeClass("active_s");

            jQuery("#duyuru_slider div .con").eq(sira).animate({ top: -290 }, "slow", function () { $(this).css({ "top": "270px" }) })
            jQuery("#duyuru_slider div .con").eq(item).animate({ top: "7px" }, "slow").addClass("active_s");

            if ((count - 1) == item)
                queue = 0;
            else
                queue = item + 1;

            if (baslangic)
                baslangic = false;

            theInvertal = setInterval(Kaydir("duyuru_slider"), 100);
        }
        catch (err) {
        }
    });
});

function Kaydir(el) {
    el = el + " div";
    count = jQuery("#" + el + " .con").size();
    //jQuery(".home_box div div").hide();


    theInvertal = setInterval(function () {
        
        if (queue == 0 && !baslangic)
            jQuery("#" + el + " .con").eq(count - 1).animate({ top: -290 }, "slow", function () { $(this).css({ "top": "270px" }) });

        if (queue != 0)
            jQuery("#" + el + " .con").eq(queue - 1).animate({ top: -290 }, "slow", function () { $(this).css({ "top": "270px" }) });

        jQuery("#" + el + " .con").removeClass("active_s");

        jQuery("#" + el + " .con").eq(queue).animate({ top: "7px" }, "slow").addClass("active_s");

        if ((count - 1) == queue) {
            queue = 0;
        }
        else
            queue++;

        if (baslangic)
            baslangic = false;

    }, 10000);

    if (count == 1)
        clearInterval(theInvertal);
}

$(document).ready(function () {

    Kaydir("duyuru_slider");

});

//Images on hover animation
$(document).ready(function () {
    $(".item, .fade, .img").fadeTo("slow", 1.0); // This sets the opacity of the thumbs to fade down to 30% when the page loads
    $(".item, .fade, .img").hover(function () {
        $(this).fadeTo("fast", 0.8); // This should set the opacity to 100% on hover
    }, function () {

        $(this).fadeTo("fast", 1.0); // This should set the opacity back to 30% on mouseout
    });
});


// Accordion
$(document).ready(function () {

    //Set default open/close settings
    $('#joblist .position').hide(); //Hide/close all containers
    $('#joblist .header:first').addClass('opened').next().show(); //Add "opened" class to first trigger, then show/open the immediate next container

    //On Click
    $('#joblist .header').click(function () {
        if ($(this).next().is(':hidden')) { //If immediate next container is closed...
            $('#joblist .header').removeClass('opened').next().slideUp(); //Remove all .header classes and slide up the immediate next container
            $(this).toggleClass('opened').next().slideDown(); //Add .acc_trigger class to clicked trigger and slide down the immediate next container
        }
        return true; //Prevent the browser jump to the link anchor
    });





    //Sliding sidebar navigation
    $(document).ready(function () {
        slide("#sidebar-navigation", 10, 0, 150, .8);
    });

    function slide(navigation_id, pad_out, pad_in, time, multiplier) {
        // creates the target paths
        var list_elements = navigation_id + " li";
        var link_elements = list_elements + " a";

        // initiates the timer used for the sliding animation
        var timer = 0;

        // creates the slide animation for all list elements 
        $(list_elements).each(function (i) {
            // margin left = - ([width of element] + [total vertical padding of element])
            if ($(this).attr('class') !== 'active' && $(this).attr('class') !== 'heading') {

                $(this).css("margin-left", "0px");
                // updates timer
                timer = (timer * multiplier + time);
                $(this).animate({ marginLeft: "0" }, timer);
                $(this).animate({ marginLeft: "10px" }, timer);
                $(this).animate({ marginLeft: "0" }, timer);
            }
        });

        // creates the hover-slide effect for all link elements 		
        $(link_elements).each(function (i) {
            if ($(this).parent().attr('class') !== 'active' && $(this).parent().attr('class') !== 'heading') {
                $(this).hover(
			function () {
			    $(this).animate({ marginLeft: pad_out }, 150);
			},
			function () {
			    $(this).animate({ marginLeft: pad_in }, 150);
			});
            }
        });
    }



});





$(document).ready(function () {
    $("a[rel^='prettyPhoto']").prettyPhoto();
});
