t = undefined;
$(document).ready(function() {

    // Windows Specific js
    var client = $.client.browser;
    var os = $.client.os;

    if ((os == 'Windows') && (client == 'Chrome' || 'Firefox')) {
        $('ul#menu-navigation li a').css('line-height', '18px');
        $('ul.latest-projects li.project-32 h2').css('margin-top', '155px');
        $('ul.latest-projects li.project-32 p').css('margin-top', '16px');
        $('ul.latest-projects li.project-46 h2').css('margin-top', '155px');
        $('body.page-id-23 .archive h3, body.date .archive h3').css('padding-bottom', '6px');
    }

    /*--------------------------------------------------------------------------------
	Home Page
	---------------------------------------------------------------------------------*/

    // $(".ie7 .page-id-16 .main-container").css("position","fixed");
    $('.latest-projects').after('<div class="buttons">')
    .cycle({
        fx: 'fade',
        speed: 1000,
        timeout: 10000,
        pager: '.buttons'
    });

    //Open tweets in new window
    $('.home-tweets a').click(function() {
        $(this).attr('target', '_blank');
    });

    //showreel video with overlay
    $(".showreel-video").click(function() {
        $(".ie7 .page-id-16 .main-container").css("position", "static")
    });

    //Jquery tools overlay
    $(".showreel-video").overlay({
        mask: {
            color: '#231F20',
            loadSpeed: 200,
            opacity: 0.9
        },
        onBeforeLoad: function() {

            var wrap = this.getOverlay().find(".contentWrap");

            wrap.load("http://drumbeatcreative.co.uk/showreel-video .drumbeatVid");

            $(".ie7 .page-id-16 .main-container").css("position", "static")

        },
        onClose: function() {
            //fix to IE7 so content appears above overlay
            $(".ie7 .page-id-16 .main-container").css("position", "relative");
            $('video')[0].pause();
        }
    });

    /*--------------------------------------------------------------------------------
	Work Page
	---------------------------------------------------------------------------------*/
	
	/*
    var ua = $.browser;
    var width = $(window).width();
    var height = $(window).height();

    var container_height = $('.scroll-wrapper').height();
	*/
	var height = $(window).height();
	console.log(height);
    $.fn.hoverscroll.params = $.extend($.fn.hoverscroll.params, {
        vertical: true,
        width: 500,
        height: height,
        arrows: true,
        fixedArrows: true
    });

	$('#scroller').hoverscroll({
        debug: false
    });

	/*
    function positionBottomScrollButton() {
        var vPos = $(window).height() + 60;
        $('div.bottom').css("top", vPos + "px");
    }

    $(window).bind('resize',
    function() {
        positionBottomScrollButton();
    });

    setTimeout(function() {
        positionBottomScrollButton();
    },
    1000);

    // Generate hoverscroll with overridden default parameters
    $('#scroller').hoverscroll({
        debug: false
    });
	*/
	
    // Ajax Request for project images
    $('.page-id-104 dt a, .single dt a').click(function() {

        //save link into loadUrl variable to be used in request
        var loadUrl = $(this).attr('href');

        //When user clicks links clear any existing timeout delays
        clearTimeout(t);
        $.ajax({
            url: loadUrl,
            // before sending request set the scroller position to zero
            beforeSend: function(xhr) {
                $('#scroller').parent()[0]['scrollTop'] = 0;
            },
            success: function(data, status, xhr) {
                //Empty the scroller
                $('#scroller').empty();
                // if user already click a project remove existing loader
                $('.loader').remove();
                // Create the loader
                $('#scroller').before('<span class="loader">loading content</span>');
                // Hide the scroller to stop users from scrolling while loading
                $('#scroller').hide();
                // Clear any other timeouts existing
                clearTimeout(t);
                // Set a timer of 1.5 secs
                t = setTimeout(function() {
                    // Remove loader
                    $('.loader').remove();
                    // Get the contents of single images
                    $('#scroller').html($(data).find(".single-images"));
                    // Show the scroller to enable scrolling
                    $('#scroller').show();
                    $('.ie7 #scroller').css('margin-top', '4px');
                },
                1500);
            }
        });
    });

    //Project name accordion effect
    $(".accordion").accordion({
        active: false,
        collapsible: true,
        autoHeight: false,
        navigation: true,
        change: function(event, ui) {

            $('.main-content').prepend('<div class="blank"></div>')
            $.doTimeout(3000,
            function() {
                $('.blank').remove();
            });

        }
    });

    /*--------------------------------------------------------------------------------
	Latest Page
	---------------------------------------------------------------------------------*/

    $('.latest-stories dl dd').hide();
    $('.latest-stories dl dt a').toggle(
    function() {
        $(this).parent().next().slideDown();
    },
    function() {
        $(this).parent().next('.latest-stories dl dd').slideUp();
    }
    );
    // Close

    // Highlight 'latest' in navigation on single blog page
    $(".single ul li.menu-item-218, .archive ul li#menu-item-218").addClass('current-menu-item');

    // Clear input when click in email box and reinstate after
    $("#osdyr-osdyr").clearInput();

    // Validate users email address on email signup
    $("#subForm").validate({
        success: function(label) {

            label.addClass("valid").text("Thanks!")
        },
        submitHandler: function(form) {
            $('input#osdyr-osdyr, input.email-signup-btn').css('display', 'none');
            form.submit();
        }
    });

    /*--------------------------------------------------------------------------------
	Contact Page
	---------------------------------------------------------------------------------*/

    $('a.drumbeat-twitter').click(function() {

        $(this).attr('target', '_blank');
    });

});


