﻿var photoItems = [
    {url: "/photo/s/075ffafaa0ad7d0e68e91aab18c73818.jpg", title: ""},
    {url: "/photo/s/09e6b41dc89dfddc2b9d10d51e35fa4b.jpg", title: ""},
    {url: "/photo/s/0d204f41c9f828c9b42a0f64500ba21b.jpg", title: ""},
    {url: "/photo/s/17fff3e233745ee93b32e41c806fd055.jpg", title: ""},
    {url: "/photo/s/18ccd61b77725060d98eecd6a2e17e2e.jpg", title: ""},
    {url: "/photo/s/1a5a619930ba746faf262048917c5c0f.jpg", title: ""},
    {url: "/photo/s/1cc9f92750c177db3f57c7ef772bf951.jpg", title: ""},
    {url: "/photo/s/1f729c0af464dc80c801582f72b76367.jpg", title: ""},
    {url: "/photo/s/2406281c191d06eba980e74fe39551d3.jpg", title: ""},
    {url: "/photo/s/246c8a6e6f1e052296aa673567ba3320.jpg", title: ""},
    {url: "/photo/s/2654cf1333cdd9d437adf3d889ee1301.jpg", title: ""},
    {url: "/photo/s/2880ffa839023833ec2dc591de4d7bda.jpg", title: ""},
    {url: "/photo/s/29f35ce99d7a29d12d4e1f69b6415257.jpg", title: ""},
    {url: "/photo/s/300d7eec2ba679e24b8fd3570a2b8b43.jpg", title: ""},
    {url: "/photo/s/39eff00829e1700f90cb8ec0ef8faed0.jpg", title: ""}
];
var stepScroll = 5;
var scrollTimer;
var wrapperWidth = 1000;
function getPhotoItemHTML(item){
    var url_m = item.url.replace('/s/', '/b/');
    return '<a href="' + url_m + '" title="' + item.title + '" rel="photo_group"><img src="' + item.url + '" width="75" height="75" border="0" alt="' + item.title + '" /></a>';
}
function scrollThumbs(step) {
    var thumbs = $("#galleryLineWrapper");
    thumbs.css("marginLeft", parseInt(thumbs.css("marginLeft")) + step + "px");
    checkArrs();
    scrollTimer = setTimeout(function() {
        scrollThumbs(step)
    }, 10);
}
function checkArrs() {
    var thumbs = $("#galleryLineWrapper");
    var thumbsWidth = thumbs.width();
    var thumbList = $("#galleryLineContent");
    if (-parseInt(thumbs.css("marginLeft")) >= (thumbsWidth - wrapperWidth)) {
        thumbList.not(".rightPosition").addClass("rightPosition");
        thumbs.css("marginLeft", -(thumbsWidth - wrapperWidth) + "px");
    } else {
        thumbList.removeClass("rightPosition");
    }
    if (parseInt(thumbs.css("marginLeft")) >= -5) {
        thumbList.not(".leftPosition").addClass("leftPosition");
        thumbs.css("marginLeft", "-5px");
    } else {
        thumbList.removeClass("leftPosition");
    }
}
$(document).ready(function(){
   var gLine = $("#galleryLine");
    gLine.html('<div id="galleryLineContent" class="leftPosition rightPosition"><a id="prevEvent" href=""></a><a id="nextEvent" href=""></a><div id="galleryLineWrapper"></div></div>').slideDown('fast', function(){
        gLine.addClass('ready').removeAttr('style');
        var gWrapper = $("#galleryLineWrapper").width(photoItems.length * 80);
        for (var i = 0; i < photoItems.length; i++) {
            var item = $(getPhotoItemHTML(photoItems[i])).get(0);
            gWrapper.append(item);
        }

        $("a[rel=photo_group]").fancybox({
            'transitionIn'		: 'none',
            'transitionOut'		: 'none',
            'titlePosition' 	: 'over',
            'titleFormat'		: 'none'
        });

        $("#prevEvent").bind("mouseenter", function() {
            clearTimeout(scrollTimer);
            scrollTimer = scrollThumbs(stepScroll)
        }).bind("mouseleave", function() {
            clearTimeout(scrollTimer);
        }).bind("click", function() {
            return false;
        });
        $("#nextEvent").bind("mouseenter", function() {
            clearTimeout(scrollTimer);
            scrollTimer = scrollThumbs(-stepScroll)
        }).bind("mouseleave", function() {
            clearTimeout(scrollTimer);
        }).bind("click", function() {
            return false;
        });
        checkArrs();
    });

    $(".coursesTabs").delegate("#personalTab","click",function(){
        $("#groupTab").removeClass("active");
        $(this).not(".active").addClass("active");

        $("#groupHolder").hide();
        $("#personalHolder").show();
        /*
        $("#groupHolder").slideUp("fast", function(){
            $(this).removeClass("active");
            $("#personalHolder").not(".active").addClass("active").slideDown("fast");
        });
        */
    });
    $(".coursesTabs").delegate("#groupTab","click",function(){
        $("#personalTab").removeClass("active");
        $(this).not(".active").addClass("active");

        $("#personalHolder").hide();
        $("#groupHolder").show();
        /*
        $("#personalHolder").slideUp("fast", function(){
            $(this).removeClass("active");
            $("#groupHolder").not(".active").addClass("active").slideDown("fast");
        });
        */
    });
});









function mycarousel_itemLoadCallback(carousel, state)
{
    for (var i = carousel.first; i <= carousel.last; i++) {
        if (carousel.has(i)) {
            continue;
        }

        if (i > mycarousel_itemList.length) {
            break;
        }

        // Create an object from HTML
        var item = $(mycarousel_getItemHTML(mycarousel_itemList[i-1])).get(0);

        // Apply thickbox
        tb_init(item);

        carousel.add(i, item);
    }
};

/**
 * Item html creation helper.
 */
function mycarousel_getItemHTML(item)
{
    var url_m = item.url.replace('/s/', '/b/');
    return '<a href="' + url_m + '" title="' + item.title + '"><img src="' + item.url + '" width="75" height="75" border="0" alt="' + item.title + '" /></a>';
};
