var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);
createPlayer({file:"DM",type:"rtmp"},"Activeplayer","bottom","none",320,250,"false","true","fullscreen","transparent","none","44700A","FFFFFF","","");
jQuery.noConflict();
jQuery(document).ready(function(){
	jQuery("#CommentAddForm").ajaxForm({target:"#err_msg",success:raspuns_server});
	function raspuns_server(responseText, statusText, xhr, $form){
		if (responseText.substr(0,2)=="OK"){
			jQuery("#err_msg").html('Your comment was submited for moderation.');
			jQuery("#err_msg").css('color',"#ff0000");
			jQuery("#err_msg").css('font-weight',"bold");
			jQuery("#CommentAddForm").fadeOut();
			setTimeout('jQuery("#comment_add").fadeOut()',15000);
		}
		else if (responseText.substr(0,10) == "ErrCaptcha")
			{
			jQuery("#err_msg").html('Invalid Captcha code, please try again.');
			jQuery("#err_msg").css('color',"#ff0000");
			jQuery("#err_msg").css('font-weight',"bold");
			refresh_captcha('comment')
			}
		else if (responseText.substr(0,7) == "ErrName")
			{
			jQuery("#err_msg").html('Invalid name, please try again.');
			jQuery("#err_msg").css('color',"#ff0000");
			jQuery("#err_msg").css('font-weight',"bold");
			refresh_captcha('comment')
			}
		else if (responseText.substr(0,6) == "ErrCom")
			{
			jQuery("#err_msg").html('The comment cannot be empty, please try again.');
			jQuery("#err_msg").css('color',"#ff0000");
			jQuery("#err_msg").css('font-weight',"bold");
			refresh_captcha('comment')
			}
	}
	//End of captcha
	jQuery("#UserRegisterForm").ajaxForm({target:"#err_msg",success:raspuns_reg});
	function raspuns_reg(responseText, statusText, xhr, $form){
		if (responseText.substr(0,2)=="OK"){
			jQuery("#err_msg").html('Account created, please check your e-mail for the confirmation letter.');
			jQuery("#err_msg").css('color',"#ff0000");
			jQuery("#err_msg").css('font-weight',"bold");
			jQuery("#UserRegisterForm").toggle();
			jQuery("#confirmAcc").toggle();
		}
		else
			{
				jQuery("#err_msg").html(responseText);	
				jQuery("#err_msg").css('color',"#ff0000");
			jQuery("#err_msg").css('font-weight',"bold");
			}
	}
	jQuery("#confirmAcc").ajaxForm({target:"#err_msg",success:raspuns_act});
	function raspuns_act(responseText, statusText, xhr, $form){
		if (responseText.substr(0,2)=="OK"){
			jQuery("#err_msg").html('Account activated. Thank you.');
			jQuery("#err_msg").css('color',"#ff0000");
			jQuery("#err_msg").css('font-weight',"bold");
		}
		else
			{
				jQuery("#err_msg").html("The username or the activation code is invalid.");	
				jQuery("#err_msg").css('color',"#ff0000");
			jQuery("#err_msg").css('font-weight',"bold");
			}
	}
	//End of new user
	jQuery( "#progressbar" ).progressbar({
			value: 25
		});
		jQuery( "#viewvid" ).tabs();
		jQuery( "#viewdocs" ).tabs();

	jQuery( "#adddoc" ).button();
	jQuery( "#adddocs" ).tabs();
		jQuery( "#addvids" ).tabs();

     jQuery( "#Login" ).button();
	jQuery( "#forum-list" ).accordion();
	jQuery( "#document-list" ).accordion({icons:false});

	jQuery( "#video-list" ).accordion();
	jQuery( ".column" ).sortable({
			connectWith: ".column"
		});

		jQuery( ".portlet" ).addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
			.find( ".portlet-header" )
				.addClass( "ui-widget-header ui-corner-all" )
				.prepend( "<span class='ui-icon ui-icon-minusthick'></span>")
				.end()
			.find( ".portlet-content-in").hide()
			.find( ".portlet-content" );

		jQuery( ".portlet-header .ui-icon" ).click(function() {
			jQuery( this ).toggleClass( "ui-icon-minusthick" ).toggleClass( "ui-icon-plusthick" );
			jQuery( this ).parents( ".portlet:first" ).find( ".portlet-content" ).toggle();
			jQuery( this).parents( ".portlet:first").find(".portlet-content-in").toggle();
		});

		jQuery( ".column" ).disableSelection();
	//now_on_air();
	jQuery("#datepicker").datepicker({
				firstDay: 1,
				navigationAsDateFormat: true,
				dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
				monthNames: ['January','February','March','April','May','June','July','August','September','Octomber','November','December'],							
				numberOfMonths: [1, 1],
				showCurrentAtPos: 0,
				beforeShowDay: highlightDays,
				dateFormat:"yy-mm-dd",
				onSelect: function(date) {
        			document.location.href="/events/view/"+date;
    			}

			});
	jQuery( "#confirmAcc" ).toggle();
	jQuery( "#bday").datepicker(
			{
				firstDay: 1,
				navigationAsDateFormat: true,
				numberOfMonths: [1, 1],
				showCurrentAtPos: 0,
				dateFormat:"yy-mm-dd",
				changeMonth: true,
				altField: "#dday",
				yearRange: '1920:1999',
				changeYear: true,
				minDate: "-90Y"
			});
//dialog forms go here
		

	//new user
	jQuery('#userAdd').click(function() {
					jQuery('#user-add').dialog('open');
			});
	if (document.getElementById("user-add")){
			
			jQuery("#user-add").dialog({
				autoOpen: false,
				height: 250,
				width:370,
				modal: true,
				open: function(event, ui){
					document.getElementById('captcha').innerHTML = '<img border="0" src="/pages/captcha/'+ Math.random() + '">';
				},
				buttons: {
					'Login': function() 
									{
										jQuery('#UserLogin').submit();
										jQuery(this).dialog('close');
									},
									
					Cancel: function() {
						jQuery(this).dialog('close');
					},
					'Register': function() 
									{
										window.location.href = '/pages/register';
										jQuery(this).dialog('close');
									},
				},
				close: function() {
					allFields.val('').removeClass('ui-state-error');
				}
			});
			



		}

});
//Carusel
 jQuery(document).ready(function() {		
           jQuery("#carusel").mbScrollable({
	            width:280,
                elementsInPage:4,
                elementMargin:1,
                shadow:"#999 2px 2px 2px",
                height:"auto",
                controls:"#controls",
                slideTimer:1000,
                autoscroll:false,
                scrollTimer:4000
            });

            setTimeout(function(){jQuery("#wrapper").fadeIn();},2000);
        });



//Carousel Tweaking

function mycarousel_initCallback(carousel) {
	
	// Pause autoscrolling if the user moves with the cursor over the clip.
	carousel.clip.hover(function() {
		carousel.stopAuto();
	}, function() {
		carousel.startAuto();
	});
}
function highlightDays(date) {
	for (var i = 0; i < dates.length; i++) {
		if (new Date(dates[i]).toString() == date.toString()) {         
			return [true, 'highlight'];
		}
	}
	return [true, ''];
} 
function split( val ) {
			return val.split( /,\s*/ );
		}
		function extractLast( term ) {
			return split( term ).pop();
		}

