jQuery(document).ready(function(){

/*
	if($(".container .sociable")){
		var htmlStr = $(".container .sociable").html();
	    $(".footer .sociable").html(htmlStr);
	    $(".container .sociable").remove();
    } */

	/*=== CLICK EVENT LISTENER
	==================================================*/

	/*
	jQuery('body').bind("click", function(e){
		// Locate the html tag that was clicked.
		var tagElement = e.target;
		
		// Identifying the tag's classname to check if it has functions assigned to it.
		// If so, execute the assigned functions.
		
		if(jQuery(tagElement).hasClass('individualProf') || jQuery(tagElement).closest('a').hasClass('individualProf')){
			alert('you clicked on a profile item');
		}
		
	});
	*/

	
	/*=== PROFILES IN DEBATE MODAL
	==================================================*/	

	var modalUtil = {
		resizer: function (){
			if ((document.documentElement.clientHeight < document.body.clientHeight) || (window.innerHeight < document.body.clientHeight)){
				jQuery('.modalBkgd').css('height', document.body.clientHeight);
			} else {
				if(jQuery.browser.msie){
					jQuery('.modalBkgd').css('height', document.documentElement.clientHeight);
				} else {
					jQuery('.modalBkgd').css('height', '100%');
				}	
			}
		}
	};
		
	window.onresize = function(){
		modalUtil.resizer();
	};
	
	jQuery('.individualProf').click(function(){
		modalUtil.resizer();
		if(jQuery.browser.msie){
			jQuery('select').css('visibility', 'hidden');
		}	
		
		var imagesrc = jQuery(this).find('img').attr('src');
		var profilenametext = jQuery(this).find('.profilename').text();
		//alert(imagesrc);
		var link = jQuery(this).attr("href") + "&mode=ajax";
		var jsonlink = jQuery(this).attr("href") + "&json=1&exclude=comments&custom_fields=profile_class,profile_school";
		
		jQuery.getJSON(jsonlink,{},function(data){

		var modalWindow = jQuery('<div/>').addClass('modal-window');		
		var profileImage = jQuery('<img/>').attr({src:imagesrc}).css({padding:'3px',border:'#c0c1c5 solid 1px',backgroundColor:'#ffffff'});
		var profileName = jQuery('<h2/>').text(profilenametext);
		var profileSchool = jQuery('<h3/>').text(data.post.custom_fields.profile_school[0]);
		var profileClass = jQuery('<h4/>').text(data.post.custom_fields.profile_class[0]);
		var scrollableArea = jQuery('<div/>').addClass('scrollable-area').html(data.post.content);
		
		modalWindow.append(profileImage).append(profileName).append(profileSchool).append(profileClass).append(scrollableArea);
			jQuery(".ajaxDataArea").html(modalWindow);
			jQuery('.profilesContentHolder').css("opacity", .5);
			jQuery('.modalWindow').slideDown('slow');
		});
		
		return false;
	});
	

	jQuery('.modalEnd').click(function(){
		jQuery('.profilesContentHolder').css("opacity", 1);
		jQuery('.modalWindow').slideUp();
		if(jQuery.browser.msie){
			jQuery('select').css('visibility', 'visible');
		}
	});
	
	
	
	/*=== MAIN NAV DROPDOWN MENUS
	==================================================*/	
	$('.mainNav').children('li.contenttab').each(function(){
		$(this).hover(function(){
			if(!$(this).hasClass('lefttab')){
				$(this).addClass('hovertab');
			}
			$(this).children('.subnav').slideDown(140);
		},function(){
			$(this).removeClass('hovertab');
			$(this).children('.subnav').stop(true,true).slideUp(140);
		});
		
		$(this).children('.subnav').css('min-width',($(this).width() + 45)+'px');
	})


	/*=== RESOURCES PAGES
	==================================================*/		
	var resourceslist = $('.resourceslist')
	
	var showall = $([]);
	
	var shadearrow = $("<span/>").addClass('shadearrow');
	var allarrows = $([]);
	
	var showalllink = $('<a/>').css({float:'right',border:'black solid 1px',padding:'3px',display:'block'}).attr({href:'#'}).text('Show all').prependTo(resourceslist).click(function(event){
		event.preventDefault();
	
		if($(this).hasClass('showingall')){
			showall.hide().siblings().children('.shadearrow').removeClass('shadearrowopen');
			$(this).text('Show all');
		}else{
			showall.show().siblings().children('.shadearrow').addClass('shadearrowopen')
			$(this).text('Hide all');
		}
		$(this).toggleClass('showingall');
		
	})
	
	
	
	resourceslist.children('ul').find('li').each(function(){
		var mychildul = $(this).children('ul');
		if(mychildul.size() > 0){
			showall = showall.add(mychildul.get());
			$(this).css({cursor:'pointer'});
			mychildul.hide();
			$(this).children('h3,h4,h5,h6,h7').addClass('togglehandle').prepend(shadearrow.clone()).click(function(){
				mychildul.toggle();
				$(this).children('.shadearrow').toggleClass('shadearrowopen');
			});
		};
	});

	
});
