﻿$.fn.anchorAnimate = function(settings) {
    settings = jQuery.extend({
        speed: 800
    }, settings);

    return this.each(function() {
        var caller = this
        $(caller).click(function(event) {
            event.preventDefault()
            var locationHref = window.location.href
            var elementClick = $(caller).attr("href")

            var offset = $(elementClick).offset();
            if (offset) {
                var destination = offset.top;
                $("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination }, settings.speed, function() {
                    window.location.hash = elementClick
                });
            }
            return false;
        })
    })
}

$(document).ready(function() {
    swfobject.registerObject("FlashID");
    $("a.anchorLink").anchorAnimate();

    $('.fancyform').each(function() {
        var setting = $(this).attr('rel'), width = 760, height = 250;
        if (setting) {
            var heightObj = setting.match(/height=([0-9])*/ig);
            if (heightObj) {
                height = heightObj[0].split('=')[1];
            }
            var widthObj = setting.match(/width=([0-9])*/ig);
            if (widthObj) {
                width = widthObj[0].split('=')[1];
            }
        }
        $(this).fancybox({
            scrolling: 'no',
            overlayOpacity: 0.7,
            overlayColor: '#000',
            type: "iframe",
            showNavArrows: false,
            titleShow: false,
            height: Number(height),
            width: Number(width),
            onStart: function() {
                document.body.style.overflow = 'hidden';
            },
            onCleanup: function() {
                document.body.style.overflow = 'auto';
            }
        });
    });
    $('.fancyimage').each(function() {
        $(this).fancybox({
            overlayOpacity: 0.7,
            overlayColor: '#000',
            centerOnScroll: true,
            type: "image",
            titleShow: false
        });
    });
})
