jQuery(function()
{
    //banner
    //jQuery('.bannerContent').fadeTo(5000,0.9); 
    //jQuery('.bannerContent').fadeIn(); 
    jQuery('.contacts a').click(function()
    {
        var maskHeight = jQuery(document).height();
        var maskWidth =  jQuery(window).width();
        
        jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
        jQuery('#mask').fadeTo("slow",0.4);  
        
        jQuery( '.contactsContent' ).show();
        
        return false;
    });
    
    jQuery('.mainContent .box h2 a').click(function()
    {
        var maskHeight = jQuery(document).height();
        var maskWidth =  jQuery(window).width();
        
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
        jQuery('#mask').fadeTo("slow",0.4);  
        jQuery(this).parent('h2').siblings('.boxContentDialog').show();
        
    });
    
    jQuery('.mainContent .box .boxContentDialog .close').click(function()
    {
        jQuery(this).parents('.boxContentDialog').hide();
        jQuery('#mask, .window').hide();
    });
    
    jQuery('.mainContent .contactsContent .close').click(function()
    {
    	jQuery( '.contactsContent' ).hide();
    	jQuery('#mask, .window').hide();
    });
    jQuery('.mainContent .bannerContent .close').click(function()
    {
    	jQuery( '.bannerContent' ).fadeOut('slow');
    });
		
    jQuery('#mask').click(function()
    {
        jQuery(this).hide();
        jQuery('.boxContentDialog').hide();
        jQuery( '.contactsContent' ).hide();
    });         
    
    //jQuery( ".mainContent .box" ).draggable({ cursor: 'crosshair' });
    

    jQuery('.event').hover(
    function()
    {
        var maskHeight = jQuery(document).height();
        var maskWidth =  jQuery(window).width();
    
        jQuery(this).siblings('.eventDialog').show();
        
    }, 
    function ()
    {
        jQuery('body').find('.eventDialog').hide();
    }
    );
	
	jQuery('.newsItem a').click( function (event)
	{
		event.preventDefault();
		itemId = jQuery(this).attr('data-id');
		var maskHeight = jQuery(document).height();
        var maskWidth =  jQuery(window).width();
		var dialog = jQuery(this).parents('.boxContent').siblings('#' + itemId);
		
		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		jQuery('#mask').fadeTo("slow",0.4);
		
		dialog.show();
		
	});
	jQuery('.videoItem a').click(function(event)
	{
		event.preventDefault();
		var maskHeight = jQuery(document).height();
        var maskWidth =  jQuery(window).width();
		
		var videoId = jQuery(this).parent('li').attr('data-videoId');
		jQuery('iframe').attr('src', 'http://www.youtube.com/embed/' + videoId);

		jQuery('#mask').css({'width':maskWidth,'height':maskHeight});
		jQuery('#mask').fadeTo("slow",0.4);
		
        jQuery(this).parents('.boxContent').siblings('.boxContentDialog').show();
	});
	
	//Get Youtube video info
	
	function getYouTubeInfo(videoId, videoTitle, videoDescription)
    {
        jQuery.ajax(
        {
            url: 'http://gdata.youtube.com/feeds/api/videos/' + videoId + '?v=2&alt=json',
            dataType: 'jsonp',
            success: function (data) { parseresults(data,videoId,videoTitle,videoDescription); }
        });
    }
	
	function parseresults(data, videoId, videoTitle,videoDescription)
    {
		var title = data.entry.title.$t;
        var description = data.entry.media$group.media$description.$t;
//        var viewcount = data.entry.yt$statistics.viewCount;
//        var author = data.entry.author[0].name.$t;
		
		videoTitle.each(function()
		{
			jQuery(this).html(title);
		});
		
		videoDescription.each(function()
		{
			jQuery(this).html(description);
		});	

    }

	jQuery('.videoItem').each(function()
	{
		var videoId = jQuery(this).attr('data-videoId');
		var videoTitle = jQuery(this).find('.videoTitle');
		var videoDescription = jQuery(this).find('.videoDescription');

		getYouTubeInfo(videoId,videoTitle,videoDescription);
	
	});		

});
