﻿$(function() {
    var hover = false;
    var widths = 0;
    var elements = $('#slider ul li');
    var elementWidths = [];

    elements.each(function(i) {
        elementWidths[i] = $(this).outerWidth();
        $(this).css('left', widths)
        widths += parseInt($(this).outerWidth(), 10) + 5;
    });
    
    setInterval(function() {
        if (hover)
            return;

        elements.each(function(i) {
            var left = parseInt($(this).css('left'));
            if ((left + elementWidths[i]) < 0) {
                var max = 0;
                elements.each(function(u) {
                    var value = parseInt($(this).css('left')) + elementWidths[u] + 5;
                    if (value > max)
                        max = value;
                });

                left = max;
            }
            $(this).css('left', (left - 1) + 'px')
        });

    }, 30);

    $('#slider').hover(function() { hover = true; }, function() { hover = false; });
});


var fileTypes = {
    image: {
        fileExt: '*.png;*.jpg;*.jpeg;*.gif',
        fileDesc: 'Image (*.png, *.jpg, *.gif)'
    },
    flash: {
        fileExt: '*.flv;*.swf',
        fileDesc: 'Flash (*.flv, *.swf)'
    }
};

function uploadify(id, fileType, multi, path, authentication, onComplete) {
    $('#' + id).uploadify({
        'script': path,
        'auto': true,
        'buttonText': 'Välj bild...',
        'scriptData': { 'AuthenticationToken': authentication },
        'fileExt': fileType.fileExt,
        'fileDesc': fileType.fileDesc,
        'multi': multi,
        'displayData': 'speed', // or Percentage
        'onComplete': onComplete != null ? onComplete : function() { }
    });
}

function uploadify1(id, fileType, multi, path, authentication, onComplete) {
    $('[name=' + id + ']').uploadify({
        'script': path,
        'auto': true,
        'buttonText': 'Välj bild...',
        'scriptData': { 'AuthenticationToken': authentication },
        'fileExt': fileType.fileExt,
        'fileDesc': fileType.fileDesc,
        'multi': multi,
        'displayData': 'speed', // or Percentage
        'onComplete': onComplete != null ? onComplete : function() { }
    });
}

function tinyMce(selector) {
    $(selector).tinymce({
        // Location of TinyMCE script
        script_url: rootDir + 'assets/scripts/libs/tiny_mce/tiny_mce.js',

        // General options
        theme: "advanced",
        plugins: "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1: "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect",
        theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,cleanup,removeformat,|,bullist,numlist,|,blockquote,|,undo,redo,|,link,unlink,image,|,styleprops,code",
        theme_advanced_buttons3: "",
        theme_advanced_toolbar_location: "top",
        theme_advanced_toolbar_align: "left",
        theme_advanced_statusbar_location: "bottom",
        theme_advanced_resizing: true,

        // Example content CSS (should be your site CSS)
        content_css: rootDir + "assets/stylesheets/main.css",

        // Drop lists for link/image/media/template dialogs
        template_external_list_url: "lists/template_list.js",
        external_link_list_url: "lists/link_list.js",
        external_image_list_url: "lists/image_list.js",
        media_external_list_url: "lists/media_list.js"
    });
}
