/**
 * @author yannickvandergoten
 */

 $(document).ready(init);
 
 
 function init()
 {
     $.ajaxSetup({
		error:function(XMLHttpRequest,textStatus,errorThrown)
		{
			console.log('Error: [' + textStatus + '] ' + errorThrown + ' : ' + XMLHttpRequest.statusText);
		},
		timeout:5000

	})
     
     loadFacebookApi();
     loadTabs();
     innerFade();

    
     $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?id=67792008@N07&lang=en-us&format=json&jsoncallback=?", displayImages);

     $('.triggerPopupTraingsuren').live('mouseover', function(){
        $('.trainingsurenPopup').fadeIn('fast');
     });

     $('.triggerPopupTraingsuren').live('mouseout', function(){
        $('.trainingsurenPopup').fadeOut('fast');
     });


 }
 function loadFacebookApi()
 {
 	FB.init({
	    status : true, // check login status
	    cookie : true, // enable cookies to allow the server to access the session
	    xfbml  : true  // parse XFBML
    });
 }

function displayImages(data) {

    // Start putting together the HTML string
    var htmlString = "";
    var firstItem = true;

    // Now start cycling through our array of Flickr photo details
    $.each(data.items, function(i,item){

        if(firstItem)
        {
           // I only want the ickle square thumbnails
            var sourceSquare = (item.media.m).replace("_m.jpg", "_m.jpg");

            // Here's where we piece together the HTML
            htmlString += '<li><a href="' + item.link + '" target="_blank">';
            htmlString += '<img title="' + item.title + '" src="' + sourceSquare;
            htmlString += '" alt="'; htmlString += item.title + '" />';
            htmlString += '</a></li>';
            htmlString += '<div class="dummy"></div> ';
            firstItem = false;
        }
        else
        {
           // I only want the ickle square thumbnails
            var sourceSquare = (item.media.m).replace("_m.jpg", "_s.jpg");

            // Here's where we piece together the HTML
            htmlString += '<li><a href="' + item.link + '" target="_blank">';
            htmlString += '<img title="' + item.title + '" src="' + sourceSquare;
            htmlString += '" alt="'; htmlString += item.title + '" />';
            htmlString += '</a></li>';
        }

         if ( i == 4 ) return false;


    });

    htmlString += '<div class="dummy"></div> ';

    // Pop our HTML in the #images DIV
    $('#photoContainer').html(htmlString);
    $('#photoContainer .preloader').css('display: none');

    // Close down the JSON function call
}

function loadTabs()
 {
 	//When page loads...
	$(".tab_content").hide(); //Hide all content
	$("ul.tabs li:first").addClass("activeTab").show(); //Activate first tab
	$(".tab_content:first").show(); //Show first tab content

	//On Click Event
	$("ul.tabs li").click(function() {

		$("ul.tabs li").removeClass("activeTab"); //Remove any "active" class
		$(this).addClass("activeTab"); //Add "active" class to selected tab
		$(".tab_content").hide(); //Hide all tab content

		var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
		$(activeTab).fadeIn(); //Fade in the active ID content
		return false;
	});
 }

function innerFade()
 {
    $('#mainSponsors').innerfade({
            speed: 'slow',
            timeout: 2500,
            type: 'sequence'
    });

        
 }



