$(document).ready(function(){
	
	//Reveal and hide the profile options
	$('a.profile-button').click(function(event){
		event.preventDefault();
		$('#profile-options').slideToggle('fast');
	});
	
	$('*:not(a)').click(function(event) {
		if($('#profile-options').attr('style')=='display: block'){
		} else {
		//$('a.comment-options').trigger('click');
		//$('a.reply-options').trigger('click');
		$('#profile-options').hide();
		};
	
	});
		
	// Style the profile option on hover
		
	$('#profile-options a').click(function(){

	});	
   
	$('#profile-options a').hover(
 	     function () {
 	     	var optionid = $(this).attr('id');

		},
       	function () {
       	var optionid = $(this).attr('id');
	});
	
	// Link the main tabs  and style on hover  
	$('.tab').click(function(){
		var tabid = $(this).attr('id');
		var rel = $('#'+tabid+' a').attr('href');
		  window.location.href = (''+rel);
		  return false;
	});	
   
	$('.tab').hover(
 	     function () {
 	     	var tabid = $(this).attr('id');
       	 $('#'+tabid+' .tabbed-nav-off-centre a span').each(function(idx,el){
    		el.style.color='#7591a1';
		});
		},
       	function () {
       	var tabid = $(this).attr('id');
		$('#'+tabid+' .tabbed-nav-off-centre a span').each(function(idx,el){
    		el.style.color='#526c7b';
		});
	});
	
	if($.getURLParam("nopermission")){
		alert('Sorry... You don\'t have the correct privileges to do that!');
		//$('body').append('<div id="alert-modal" style="display: none;"><p>You don\'t have permission to do that</p></div>');
		//$('#alert-modal').fadeIn();
	}

	if($.getURLParam("sizealert")){
		alert('Sorry... You don\'t enough AllWorkedUp memory to do that! Perhaps look into upgrading your account?');
		//$('body').append('<div id="alert-modal" style="display: none;"><p>You don\'t have permission to do that</p></div>');
		//$('#alert-modal').fadeIn();
	}
		
	//var hiddencount = $('div.project-thumbs-contain:visible', document.body).length;
	if($.browser.msie || $.browser.mozilla){
	
		var hiddendepth = $('.hidden-thumbs').height();
			//alert(hiddendepth);		
		pthumbHeight(hiddendepth);
		
	} else {
	
		$(".hidden-thumbs .project-thumbs-contain a img:last").load(function(){
			var hiddendepth = $('.hidden-thumbs').height();
			//alert(hiddendepth);		
			pthumbHeight(hiddendepth);
		});
	
	}
		
		
	$('h3.filter-select').click(function(event){
		event.preventDefault();
		$('.filter-options').slideToggle('fast');
	});
	
	$('*:not(a)').click(function(event) {
		if($('.filter-options').attr('style')=='display: block'){
		} else {
		//$('a.comment-options').trigger('click');
		//$('a.reply-options').trigger('click');
		$('.filter-options').hide();
		};
	});
	
	$('.overview-column1 textarea').rte({
		css: ['css/jquery.rte.css'],
		width: 424,
		height: 128,
	  frame_class: 'awurte',
	  controls_rte: rte_toolbar,
	  controls_html: html_toolbar
	});
	
	$('.viewer-form-wrap textarea').rte({
		css: ['css/jquery.rte.css'],
		width: 424,
		height: 80,
	  frame_class: 'awurte',
	  controls_rte: rte_toolbar,
	  controls_html: html_toolbar
	});
 	
// End jQuery object
    
});

   
// Return Id of string //
function getID(strID)
{
 return strID.replace(/[^0-9]/gi, '');
}

// Allow text in input boxes as titles //

var swap_text_boxes = [];

function init_swap_text_boxes(){
  //Store the default value for each box
  $('input[type=text][value].swaptextbox').each(function() {
    swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
  });
  //Add focus and blur events to set or clear the value
  $('input[type=text][value].swaptextbox').bind('focus', function() {
    if($(this).val() == swap_text_boxes[$(this).attr('id')]) {
      $(this).val('');
	  $(this).css({
	  'color': '#4C6A7C'
	  });
    }
  });
  $('input[type=text][value].swaptextbox').bind('blur', function() {
    if($(this).val() == '') {
      $(this).val(swap_text_boxes[$(this).attr('id')]);
	  $(this).css({
	  'color': '#B1C4CE'
	  });
    }
  });
  
} 

function delcheck() {
    return confirm("Are you sure? There are no backups! This will be completely deleted from the system!");
}

function pthumbHeight(hiddendepth) {
	if(hiddendepth > '187'){
		$('.hidden-thumbs').css({
				height: '187px'
		});
		$('.hidden-thumbs').append('<div class="showem"><a href="#" class="show-all-thumbs">Show them all</a></div><div class="showem" style="display: none;"><a href="#" class="show-all-thumbs">Show a few</a></div>');
	
		$('a.show-all-thumbs').click(function(event){
			if($('.hidden-thumbs').css('height') == 'auto'){
				$('.hidden-thumbs').css({
					height: '187px'
				});
				$('.showem').toggle();
			} else {
				$('.hidden-thumbs').css({
					height: 'auto'				
				});
				$('.showem').toggle();
			}
		});
	
	} else {
			$('.hidden-thumbs').css({
				height: '167px'
			});	
	}
}

function expcheck() {
    return confirm("Are you sure? The project will not be accessible, however you will be able to restore the project from your dashbard for the next 14 days.");
}

function membercheck() {
    return confirm("Are you sure? This will prevent this user accessing this project!");
}

function findHHandWW() {
imgHeight = this.width;
imgWidth = this.width;
return true;
}

function showImage(imgPath) {
var myImage = new Image();
myImage.name = imgPath;
myImage.onload = findHHandWW;
myImage.src = imgPath;
}

function stripAnch(id){
	//Remove anchor from url
	var id;
	var anchor_index = id.indexOf('#');
    if (anchor_index != -1) {
    	id = id.substring(0, anchor_index);
    }  
   return id;
}