﻿
$(function () {

    $('#otherscrollers').cycle();
    $('#fade').cycle();
    $('#curtainX').cycle();

    $("#tweetboard").tweet({
        join_text: "auto",
        query: "Langhenkel Volley",
        avatar_size: 75,
        count: 1,
        auto_join_text_default: "",
        auto_join_text_ed: "",
        auto_join_text_ing: "",
        auto_join_text_reply: "",
        auto_join_text_url: "",
        loading_text: "tweets laden..."
    });

    if ($('#photo-board').length > 0) {
        $("#photo-board").pwi({
            username: '104175700432982016519',
            maxResults: 3,
            thumbSize: 90,
            thumbCrop: 1,
            mode: 'latest',
            album: '',
            thumbCss: { margin: '15px 0 10px 5px', 'float': 'left', 'width': '90px' },
            popupExt: function (photos) {
                photos.fancybox({
                    'onComplete': function () {
                        var text = $('td#fancybox-title-float-main').html();
                        $('td#fancybox-title-float-main').html(text + " - alle media");
                        $('td#fancybox-title-float-main').wrapInner("<a href='/informatie-supporter/media' style='text-decoration: none;' onClick=location.href='/informatie-supporter/media'></a>");
                    }
                })
            }
        });


        $("#photo-board-media").pwi({
            username: '104175700432982016519',
            maxResults: 6,
            thumbSize: 90,
            thumbCrop: 1,
            mode: 'latest',
            album: '',
            thumbCss: { margin: '15px 0 10px 5px', 'float': 'left', 'width': '90px' },
            popupExt: function (photos) {
                photos.fancybox({
                    'onComplete': function () {
                        var text = $('td#fancybox-title-float-main').html();
                        $('td#fancybox-title-float-main').html(text + " - alle media");
                        $('td#fancybox-title-float-main').wrapInner("<a href='/informatie-supporter/media' style='text-decoration: none;' onClick=location.href='/informatie-supporter/media'></a>");
                    }
                })
            }
        });
    };

    $.getJSON('http://gdata.youtube.com/feeds/users/topvolleydoetinchem/uploads?alt=json-in-script&callback=?&max-results=3',
	function (data) {
	    $.each(data.feed.entry, function (i, item) {
	        var title = item['title']['$t'];
	        var video = item['id']['$t'];
	        video = video.replace('http://gdata.youtube.com/feeds/videos/', 'http://www.youtube.com/watch?v=');
	        src = $.jYoutube(video);

	        var a = $('<a />').attr('target', '_blank').attr('title', title).attr('href', video).appendTo('div#tube-board');
	        a.fancybox({
	            'titleShow': false,
	            'transitionIn': 'elastic',
	            'transitionOut': 'elastic',
	            'href': video.replace(new RegExp("watch\\?v=", "i"), 'v/'),
	            'type': 'swf',
	            'swf': { 'wmode': 'transparent', 'allowfullscreen': 'true' }
	        });

	        var img = $('<img />').attr('width', 108).attr('height', 75).attr('src', src).appendTo(a);
	    });
	});

    $.getJSON('http://gdata.youtube.com/feeds/users/topvolleydoetinchem/uploads?alt=json-in-script&callback=?',
	function (data) {
	    $.each(data.feed.entry, function (i, item) {
	        var title = item['title']['$t'];
	        var video = item['id']['$t'];
	        video = video.replace('http://gdata.youtube.com/feeds/videos/', 'http://www.youtube.com/watch?v=');
	        src = $.jYoutube(video);

	        var a = $('<a />').attr('target', '_blank').attr('title', title).attr('href', video).appendTo('div#tube-board-media');
	        a.fancybox({
	            'titleShow': false,
	            'transitionIn': 'elastic',
	            'transitionOut': 'elastic',
	            'href': video.replace(new RegExp("watch\\?v=", "i"), 'v/'),
	            'type': 'swf',
	            'swf': { 'wmode': 'transparent', 'allowfullscreen': 'true' }
	        });

	        var img = $('<img />').attr('width', 90).attr('height', 63).attr('src', src).appendTo(a);
	    });
	});
});

$(function () {
    $(document).ready(function () {
        $('.mainmenu > li').bind('mouseover', openSubMenu);
        $('.mainmenu > li').bind('mouseout', closeSubMenu);

        function openSubMenu() {
            $(this).find('.submenu').css('visibility', 'visible');
        };

        function closeSubMenu() {
            $(this).find('.submenu').css('visibility', 'hidden');
        }; 
    }); 

    $('#slides').slides({
        preload: true,
        preloadImage: '/Content/images/loading.gif',
        play: 5000,
        pause: 2500,
        hoverPause: true,
        animationStart: function (current) {
            $('.caption').animate({
                bottom: -100
            }, 100);
        },
        animationComplete: function (current) {
            $('.caption').animate({
                bottom: 0
            }, 200);
        },
        slidesLoaded: function () {
            $('.caption').animate({
                bottom: 0
            }, 200);
        }
    });

    $('.pagination a').each(function () {
        $(this).html("");
    });
});

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: 2,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});

$(function () {
    $("input#searchterm").live("click", function () {
        $(this).val("");
    });

    resizeImage()
    $(window).resize(function () {
        resizeImage();
    });
});

resizeImage = function () {
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    var imgWidth = 1200;
    var imgHeight = 573;

    var windowRatio = windowWidth / windowHeight;
    var imageRatio = imgWidth / imgHeight;

    var newWidth = windowWidth;
    var newHeight = (newWidth / imgWidth) * imgHeight;

    if (imageRatio > windowRatio) { /// img is platter dan window. img moet breder dan 100% worden, height moet 100% worden.
        newHeight = windowHeight;
        newWidth = (newHeight / imgHeight) * imgWidth;
    }

    var extra = ((0.5 * newWidth) - (882 * newWidth) / imgWidth) - (((850 * newWidth) / imgWidth) / 2) + 250;
    var diff = newHeight - windowHeight;
    var topPos = 0;
    if (diff > 0) {
        topPos = -1 * (diff / 2);
    }
    if (newHeight >= 544) {
        $('div#bgimage img').css({ 'width': newWidth + 'px' });
    }
}


$(document).ready(function () {
    Cufon.replace('#header div.menu ul.mainmenu li a.item');
    Cufon.replace('.businessblock ul li a');
    Cufon.replace('span.zoom');
    Cufon.replace('.col h1');
    Cufon.replace('.businessblock .right h1');
    Cufon.now();
});
