﻿jQuery(function ($) {  
    //borrowed from jQuery easing plugin
    //http://gsgd.co.uk/sandbox/jquery.easing.php
    $.easing.elasout = function (x, t, b, c, d) {
        var s = 1.70158; var p = 0; var a = c;
        if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3;
        if (a < Math.abs(c)) { a = c; var s = p / 4; }
        else var s = p / (2 * Math.PI) * Math.asin(c / a);
        return a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b;
    };
    $('a.back').click(function () {
        $(this).parents('div.pane').scrollTo(0, 800, { queue: true });
        $(this).parents('div.section').find('span.message').text(this.title);
        return false;
    });    
    $('ul.links').click(function (e) {
        e.preventDefault();
        var link = e.target;
        link.blur();
        if (link.title)
            $(this).parent().find('span.message').text(link.title);
    });
    // Reset all scrollable panes to (0,0)
    $('div.pane').scrollTo(0);
    // Reset the screen to (0,0)
    $.scrollTo(0);
  
    $('a.scroll').click(function () {
        $.scrollTo(this.hash, 1200, {});
        $(this.hash).find('span.message').text(this.title);
        return false;
    });

    $("a.fancy").fancybox({
        'speedIn': 600,
        'speedOut': 200
    });   

    var clearMePrevious = '';
    
    $('.clearMe').focus(function () {
        if ($(this).val() == $(this).attr('title')) {
            clearMePrevious = $(this).val();
            $(this).val('');
        }
    });

    $('.clearMe').blur(function () {
        if ($(this).val() == '') {
            $(this).val(clearMePrevious);
        }
    });

    $("#mailForma").validate({
        rules: {
            poruka: {
                required: true,
                minlength: 15
                }
            }
    });

    // setup overlay actions to buttons
    $("a.video[rel]").overlay({

        expose: '#fff',

        onLoad: function (content) {
            // find the player contained inside this overlay and load it
            this.getOverlay().find("a.player").flowplayer(0).load();
        },

        onClose: function (content) {
            $f().unload();
        }
    });

    // install flowplayers
    $("a.player").flowplayer({ src: "http://www.jedansest.hr/flowplayer-3.1.5.swf" },
                { clip: { scaling: 'fit' },
                    canvas: { backgroundColor: "#000000" }
                }); 
    

});