$(document).ready(function () {
	
	
    $('#NivoSlider').nivoSlider({ 
        pauseTime:7000, 
        pauseOnHover:true,
        slices:1,
        effect:'fade',
        captionOpacity: 0.9,
        animSpeed:200
    });
    
    //center slider bullets
    var boxWidth = 734;
    var buletWidth = 22;
    var noBullets = $('.nivo-controlNav a').length;
    var leftMargin = parseInt(boxWidth/2 - buletWidth*noBullets/2);
    $('.nivo-controlNav a:first').css('margin-left',leftMargin+'px');
    $('.ie6 .nivo-controlNav a:first').css('margin-left',leftMargin/2+'px');
	
	
	//video popups
    $("#NivoSlider .video, #Header a.video, a.playVideo").click(function(e) {
	   
        e.preventDefault();
        
        var v = document.createElement('video');
        var playH264 =  !!(v.canPlayType && v.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"').replace(/no/, ''));
        $('video').remove();
        
        if(playH264){
        
            $.fancybox({
            	'padding' : 0,
            	'width' : 640,
            	'height' : 360,
            	'autoDimensions' : false,
            	'scrolling' : false,
            	'showNavArrows' : 0,
            	'overlayColor' : '#000',
            	'overlayOpacity' : 0.9,
            	'content' : '<video controls autoplay="autoplay" width="640" height="360"><source src="'+this.href+'" type="video/mp4"/></video>'
            });
        
        }else{
        
            $.fancybox({
            	'padding' : 0,
            	'width' : 640,
            	'height' : 360,
            	'autoDimensions' : false,
            	'scrolling' : false,
            	'showNavArrows' : 0,
            	'overlayColor' : '#000',
            	'overlayOpacity' : 0.9,
            	'content' : '<div id="VideoPlayerWrp">Flash Player is not installed</div>'
            });
            
            var flashvars = {
        		src: "jcPlayer640x360",
        		videoURL: this.href,
        		autoPlay: "true",
        		scaleMode: "exactFit",
        		loop: "false",
        		backgroundColor1: "0x000000",
        		backgroundColor2: "0x444444",
        		movieBackgroundColor: "0x000000",
        		inkColor: "0xffffff",
        		highlightColor: "0xB5202A",
        		playButoon: "true",
        		seekBar: "true",
        		timeBar: "true",
        		volumeButton: "true",
        		fullScreenButton: "false",
        		autoHide: "true",
        		autoHideFullScreen: "true",
        		offsetY: "25",
        		offsetYFullScreen: "25",
        		margins: "0",
        		marginsFullScreen: "0",
        		volume: "70",
        		bufferTime: "1",
        		smoothing: "auto", 
        		autoHide: "false"
            };
                	
        	var params = {};
        	var attributes = {};
        	
            swfobject.embedSWF("assets/templates/site/jcPlayer640x360.swf", "VideoPlayerWrp", "640", "360", "9.0.0", "expressInstall.swf",flashvars, params, attributes);
        }
        
        return false;
    });

    $('table tbody tr:even').addClass('even');
    
    //home pagination
    if($('#NewsHome').length > 0 ){
    	//enable home navigation
    	var perPage = 5;
    	
    	//init
    	$('#NewsHome a').show();
    	$('#NewsHome a:gt('+(perPage-1)+')').hide();
    	
    	//build navigation
    	var totalItems = $('#NewsHome a').length;
    	
    	for(i=0; i < Math.ceil(totalItems/perPage); i++){
    		$('#NewsPagination').append('<a href="#">'+ (i+1) +'</a>');
    	}
    	
    	$('#NewsPagination a').click(function(event){
    		
    		event.preventDefault();
    		
    		$('#NewsPagination a').removeClass('active');
    		$(this).addClass('active');
    		
    		var clickedPage = $(this).text();
    			
    		if(clickedPage == 1){
    			$('#NewsHome a').show();
    			$('#NewsHome a:gt('+(perPage-1)+')').hide();
    		}else{
    			$('#NewsHome a').hide();
    			$('#NewsHome a:gt('+( perPage*(clickedPage-1) - 1)+')').show();
    			$('#NewsHome a:gt('+ (( perPage*(clickedPage-1) - 1) + perPage) +')').hide();
    		}
    		
    	});
    	
    	
    }
    
});

$(window).resize(function(){
	
});

$(window).load(function () {

});
