$(document).ready(function() {



    $("a[rel=example_group]").fancybox({
        'transitionIn': 'elastic',
        'transitionOut': 'elastic',
        'titlePosition': 'over',
        'titleFormat': function(title, currentArray, currentIndex, currentOpts) {
            return '<span id="fancybox-title-over">Bild ' + (currentIndex + 1) + ' av ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
        }
    });

    $("#accordion").accordion({
        header: "h3",
        collapsible: true, 
        active: parseInt($("#accordion").attr('data-selected'))
    });



    $('#tabs').tabs();

    $("#tags").autocomplete({
        cacheLength: 0,
        minLength: 3,
        source: "http://www.agrenshuset.se/includes/html/sokord.asp",
        select: function(event, ui) {
            window.location.href = ui.item.link;
        }
    });

    $(".dialogForm").click(function(e) {
        var $loadHref = $(this).attr('href');
        var $title = $(this).attr('data-header');
        var $height = parseInt($(this).attr('data-height'));
        var $width = parseInt($(this).attr('data-width'));
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;

        var scrolledX = $(document).scrollLeft();
        var scrolledY = $(document).scrollTop();
        var posX = e.pageX - scrolledX;
        var posY = e.pageY - scrolledY;
        var tmpX = posX + $width;
        var tmpY = posY + $height;
        var tmpScrollX = scrolledX + windowWidth;
        var tmpScrollY = scrolledY + windowHeight;

        if ((tmpY) > (tmpScrollY)) { posY = posY - $height }
        if ((tmpX) > (tmpScrollX)) { posX = posX - $width }

        var $dialog = $('<div id="formDialog"></div>')
		            .load($loadHref)
		            .dialog({
		                autoOpen: false,
		                show: 'blind',
		                title: $title,
		                width: $width,
		                height: $height,
		                draggable: false,
		                resizable: false,
		                modal: false,
		                position: [posX, posY]
		            });
        $dialog.dialog('open');
        return false;
    });
    
});



function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });
 
    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};
 
jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 4,
        wrap: 'last', 
        initCallback: mycarousel_initCallback
    });
});
		

function show(obj) {
    no = obj.options[obj.selectedIndex].value;
    count = obj.options.length;
    for(i=1;i<4;i++)
    document.getElementById('SwitchDiv'+i).style.display = 'none';
    if(no>0)
    document.getElementById('SwitchDiv'+no).style.display = 'block';
}
