﻿$(document).ready(function () {
	GetTweets();
    loadToContent('/home/home');
    $('.ColorBoxContents').live('click',
    function () {
        $.get($(this).attr("href"), function (data) {
            ColorBoxIt(data, false);
        });
        return false;
    });

    $('div.pagination-clean > div >a').live('click',
	function () {
	    /*$(".hover").stop().animate({
	    'opacity': 0
	    }, 700, 'easeOutQuad')
				
	    $(".hover", this).stop().animate({
	    'opacity': 1
	    }, 700,'easeOutSine')
		
	    $(".hover", this).attr("id","clicked");
	    $(".hover :not(this)").attr("id","");
		
	    */
	    var toLoad = $(this).attr('href');
	    loadToContent(toLoad);
	    return false;
	});
	$.get('/events/popup', function (data) {
	    ColorBoxIt(data, true);
	});
	$("#jquery_jplayer_1").jPlayer({
		ready: function () {
		    $(this).jPlayer("setMedia", {
			mp3: "/Content/Player/Audio/mp3_file_1.mp3"
		    }).jPlayer("play"); 
		},
		swfPath: "/Content/Player",
		preload: "auto"	
	});
});

function ColorBoxIt(data, sshow) {
    $('#content').append('<DIV id="Tmp">' + data + '</DIV>');
    $('.LoadedCBData').colorbox({ open: true,
        rel: 'CBox',
        slideshow : sshow,
        onClosed: function () {
            $('#Tmp').remove();
        }
    });
    return data;
}
function loadToContent(toLoad)
{
    $('#content').empty().hide();
    loadContent();
	$('#load').fadeIn('normal');
    window.location.hash = '#' + toLoad;
    function loadContent() {
        $('#content').load(toLoad, '', function (response, status, xhr) {           
            $('#content').fadeIn(1000, 'easeOutSine', hideLoader());
        });       
	}

	function hideLoader() {
	    $('#load').hide();
	    $(".ColorBox").colorbox();
	}
}
function submitMsg(name, email, homepage, text) {   
    var dataString = 'Name=' + name + '&Email=' + email + '&HomePage=' + homepage + '&Text=' + text;
    $.ajax({
        type: "POST",
        url: "GB/submit",
        data: dataString,
        success: function () {
            alert('Thank You for Your post! Your post will be visible after administrator approves it.');
        }
    });
    return false;
}

$.fn.wait = function (time, type) {
    time = time || 1000;
    type = type || "fx";
    return this.queue(type, function () {
        var self = this;
        setTimeout(function () {
            $(self).dequeue();
        }, time);
    });
};
function GetTweets() {
    var TweetItems = new Array(0);
    $.jTwitter('rdmcbih', 8, function (posts) {
        var itemhtml;
        for (var i = 0; i < posts.length; i++) {
            itemhtml = '<div class="tweet">' + posts[i].text + '</div>';
            TweetItems.push(itemhtml);
        }
        InitTicker(3);
    });
    function InitTicker(count){
        var first = 0;
        var speed = 700;
        var pause = 5000;
        if (count > TweetItems.length) {
            count = TweetItems.length;
        }

        var counter = count;

        for (var i = 0; i < count; i++) {
            addLast(TweetItems[i]);
        }

        function removeFirst() {
            first = $('#tweets > div:first').html();
            $('#tweets > div:first').animate({ opacity: 0 }, speed).fadeOut('slow', function () {
                $(this).remove();
                if (counter < TweetItems.length-1) {
                    counter += 1;
                }
                else {
                    counter = 0;
                }
                addLast(TweetItems[counter]);
            });

        }
        function addLast(first) {

            last = '' + first + '';
            $('#tweets').append(last)
            $('#tweets > div:last').animate({ opacity: 1 }, speed).fadeIn('slow')
        }

        interval = setInterval(removeFirst, pause);
    }
}
