// FSTCMS namespace
var FSTCMS = window.FSTCMS || {};

// Module: FSTCMS.Site
FSTCMS.Site = (function() {
	
	var originalFontSize;
	
	var currentFontSize = function() {
		var currentFontSize = $('html').css('font-size');
		var currentFontSizeNum = parseFloat(currentFontSize, 10);
		return currentFontSizeNum;
	};
	
	// Public
	return {
	
		initVideos : function(player, list) {
            //var videos = [{image: '/video/poster-health.png', file : '/video/OpenHealth_Logo_animation_audio.mp4' }];
            var videos = [];
            $('#'+list+' a').each(function(i, o) {
                
                videos.push({ file : o.href });
                $(o).click(function(e) {
                    jwplayer(player).playlistItem(o.id.substring(o.id.lastIndexOf('-')+1, o.id.length));
                    if (typeof current != 'undefined') {
                        $(current).removeClass('current');
                    }
                    current = $(o).parent();
                    current.addClass('current');            
                    e.preventDefault();
                });
            });
            FST.Util.log(videos);
            jwplayer(player).setup({
                flashplayer : '/swf/player.swf',
                playlist : videos,
                height : 310,
                width : 566,
                autostart: true
            });
    		$('#videolistul').jcarousel({
			    vertical: true
			});	

            FST.Util.log(player);           
        },
	
		initFancyBox : function() {
			if (typeof $.fancybox !== 'function') return false;
			$('.fancy').fancybox({
		        'transitionIn'      : 'none',
		        'transitionOut'     : 'none',
		        'titlePosition'     : 'over',
		        'titleFormat'       : function(title, currentArray, currentIndex, currentOpts) {
		            return '<span id="fancybox-title-over">Image ' +  (currentIndex + 1) + ' / ' + currentArray.length + ' ' + title + '</span>';
		        }
		    });
		    $('#video-popup a').fancybox({
		    	'type'				: 'swf',
				'padding'			: 0,
				'autoScale'			: false,
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});
		},
		
		initToggle : function() {
			$('.toggle_container').hide(); 
			$('h2.trigger').click(function(){
				$(this).toggleClass('active').next().slideToggle('slow');
				return false;
			});
		},
		
		initFontResize : function() {
		 	var originalFontSize = $('html #page-container').css('font-size');
			
			function currentfs() {
				var currentFontSize = $('html #page-container').css('font-size');
				var currentFontSizeNum = parseFloat(currentFontSize, 10);
				return currentFontSizeNum;
			}
		  
		  	// Increase Font Size
		  	$(".increaseFont").click(function(){
			    var currentFontSizeNum = currentfs();
			    //console.log(currentFontSizeNum);
			    currentFontSizeNum = currentFontSizeNum*1.1;
			    //console.log(currentFontSizeNum);
			    $('html #page-container').css('font-size', Math.ceil(currentFontSizeNum));
			    return false;
		  	});
		  	// Decrease Font Size
			$(".decreaseFont").click(function(){
			    var currentFontSizeNum = currentfs();
			    currentFontSizeNum = currentFontSizeNum*0.9;
			    //console.log(currentFontSizeNum);
			    $('html #page-container').css('font-size', Math.floor(currentFontSizeNum));
			    return false;
			});
		  	// Reset Font Size
			$(".resetFont").click(function(){
		    	$('html #page-container').css('font-size', originalFontSize);
		  	});
		},
		
		initScroll : function() {
            $.scrollTo( window.location.hash+'-1' || 0, 1500);
        },
        
        initTweets : function() {
        	$(".tweet").tweet({
	        join_text: "auto",
	        username: ["openhealth"],
	        avatar_size: 48,
	        count: 5,
	        auto_join_text_default: "",
	        auto_join_text_ed: "",
	        auto_join_text_ing: "",
	        auto_join_text_reply: "",
	        auto_join_text_url: "",
	        loading_text: "loading tweets..."
	      });
        }
		
	};
	
}());

// Set up videos on homepage
FST.Util.call('', FSTCMS.Site.initVideos, FSTCMS.Site, ['videopanel', 'videolistul']);
FST.Util.call('', FSTCMS.Site.initTweets, FSTCMS.Site);
FST.Util.call('*', FSTCMS.Site.initFancyBox, FSTCMS.Site);
FST.Util.call('*', FSTCMS.Site.initToggle, FSTCMS.Site);
FST.Util.call('*', FSTCMS.Site.initFontResize, FSTCMS.Site, [document.getElementById('text-size')]);
FST.Util.call('/news', FSTCMS.Site.initScroll, FSTCMS.Site);

