﻿    var roles_selector = 0;
    $(document).ready(function() {

        Cufon.replace('h1');
        Cufon.replace('h2');
        Cufon.replace('.intro-text p.shdw');
        Cufon.replace('.box-header span');
        Cufon.replace('.menu-header ul li a', { hover: true, hoverables: { a: true} });

        var i = 0;
        var postid = new Array();
        var control_id;
        $('.tiny-carousel').each(function() {
            postid[i] = this.id; //carouselnr_83
            postid[i] = postid[i].replace('carouselnr_', ''); //83
            postid[i] = postid[i].replace('prodslide_', '');
            i++;
            
            $(this).tinycarousel({
                callback: function(element, index) {
                    var n = $('#' + this.id + ' li:eq(' + index + ')').attr('id'); //opt_83_Yellow
                    $('#sel_color_' + this.id.replace('carouselnr_', '') + '').val(n); //opt_83_Yellow_114
                    control_id = this.id.replace('opt_', '');
                    control_id = control_id.replace('carouselnr_','');
                },
                controll_element: '#sel_color_' + this.id.replace('prodslide_','') //sel_color_83
            });
        });

        $('.bigger-carousel').each(function() {
            $(this).tinycarousel();
        });


        $("#sel-btn, #select_role_pick_div").click(function() {
            if (roles_selector == 1) {
                $("#roles").hide();
                roles_selector = 0;
                $(this).attr("src", "http://www.smartshake.com/wp-content/themes/smartshake/images/sel-lft.gif");
            }
            else {
                $("#roles").show();
                roles_selector = 1;
                $(this).attr("src", "http://www.smartshake.com/wp-content/themes/smartshake/images/sel-dwn.gif");
            }
        });

        //GetYouTubeVideos();
        $("#youtube-videos").CloudCarousel({
            xPos: 140,
            yPos: 25,
            reflHeight: 22,
            reflGap: 2,
            buttonLeft: $("#left-but"),
            buttonRight: $("#right-but"),
            altBox: $("#alt-text"),
            titleBox: $("#title-text"),
            FPS: 30,
            autoRotate: 'left',
            autoRotateDelay: 3000,
            speed: 0.1,
            mouseWheel: false,
            bringToFront: true
        });

        $(".yvideos").click(function() {
            $.fancybox({
                'padding': 0,
                'autoScale': false,
                'transitionIn': 'none',
                'transitionOut': 'none',
                'title': this.title,
                'width': 640,
                'height': 385,
                'href': this.href.replace(new RegExp("watch\\?v=", "i"), 'v/'),
                'type': 'swf',
                'swf': {
                    'wmode': 'transparent',
                    'allowfullscreen': 'true'
                }
            });
            return false;
        });
        
        /*
        $("#youtube-videos a").each(function(e) {
            $('#' + this.id).fancybox({
                'width': '100%',
                'height': '100%',
                'autoScale': false,
                'transitionIn': 'none',
                'transitionOut': 'none',
                'type': 'iframe'
            });
        });
        */

    });

    function GetYouTubeVideos() 
    {
        var _thumb = '';
        var _images = '';
        var _counter = 0;        
        var _url = 'http://wp04.webbplats.se/wp-content/themes/smartshake/ajax/get.php';
        $.ajax({
            type: "get",
            dataType: "json",
            url: _url,
            async: false,
            success: function(ret) {
                if (ret != null) {
                    var _json = jQuery.parseJSON(ret);
                    if (_json.feed.entry.length > 0) {
                        for (var i = 0; i < _json.feed.entry.length; i++) {
                            _url = _json.feed.entry[i].media$group.media$content[0].url;
                            _thumb = _json.feed.entry[i].media$group.media$thumbnail[0].url;
                            _images += '<a id="vid_' + _counter + '" href="' + _url + '" class="yvideos"><img class="cloudcarousel" src="' + _thumb + '" alt="' + _json.feed.entry[i].title.$t + '" title="' + _json.feed.entry[i].title.$t + '" /></a>';
                            _counter++;
                        }
                        $("#youtube-videos").html(_images);
                    }
                }
            }
        });

    }
