function drawArrows(){
if(!$.browser.msie){
	var activeNav = $('.blogsidebarsection ul.categories li.current a');
	
	if(activeNav.size()!=0){
		var fillColor = activeNav.css('backgroundColor');
		var strokeColor = activeNav.css('backgroundColor');
		var canvasHeight = activeNav.outerHeight();
		var canvasWidth = 10;
		var arrowCanvas = $('<canvas/>').css({
					position:'absolute',
					top:'0',
					left:'-'+canvasWidth+'px',
					zIndex:'20'
				}).attr(
			{
			height:canvasHeight,
			width:canvasWidth
		});	
		
		ctx = arrowCanvas.get(0).getContext('2d');
		
		activeNav.append(arrowCanvas);
		
		ctx.fillStyle = fillColor;
		ctx.strokeStyle = strokeColor;
		ctx.beginPath();
		ctx.moveTo(canvasWidth,0);
		ctx.lineTo(0,canvasHeight/2);
		ctx.lineTo(canvasWidth,canvasHeight);
		ctx.fill();
		ctx.stroke();
	}
}
}


jQuery(document).ready(function(){

drawArrows();

 var galleries = jQuery('.ad-gallery').adGallery({loader_image:'/wp-content/themes/urbandebate/ad-gallery/loader.gif',slideshow:{enable:false},effect:'fade'});

/*
	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');
	})
	
	$('.header_nav').children('ul').children('li').each(function(){
		$(this).hover(function(){
			$(this).addClass('hover');
			$(this).children('ul').slideDown(140);
		},function(){
			$(this).removeClass('hover');
			$(this).children('ul').stop(true,true).slideUp(140);
		});
		
	})
	
	$('.header_nav > ul > li:last-child').before($('<div>').addClass('righttabfinish'));


	/*=== 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).next();
		console.log(mychildul);
		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');
			});
		};
	});
	
	
	var resources3 = $('.resources-list-v3')
	
	resources3.children('ul').find('li').each(function(){
		var mychildul = $(this).next();
		
		if(!mychildul.eq(0).is('ul')){
			mychildul = $([]);
		}
		
		if(mychildul.size() > 0){
			showall = showall.add(mychildul.get());
			$(this).css({cursor:'pointer'});
			mychildul.hide();
			$(this).children('strong,h3,h4,h5,h6,h7').addClass('togglehandle').prepend(shadearrow.clone()).click(function(){
				mychildul.toggle();
				$(this).children('.shadearrow').toggleClass('shadearrowopen');
			});
		};
	}).children('.resource').each(function(){
	
		$(this).children('.resource-content').hide();
		$(this).children('.resource-header').children('.title').css('cursor','pointer').addClass('togglehandle').prepend(shadearrow.clone()).click(function(){
			$(this).parent().siblings('.resource-content').toggle();
			$(this).children('.shadearrow').toggleClass('shadearrowopen');
		})
	
	})

	$('#resource-tabs').tabs();
	
	/*=== VIDEO EXPAND AND SHOW
	==================================================*/
	

	
	$('.videoRow').css('cursor','pointer').click(function(){
		console.log($(this));
		//alert('open sesame');
		$(this).find('.videoMedia').show();
		$(this).find('.videoThumb').hide();
		$(this).find('.videoDescription').hide();
		$(this).unbind('click');
		

		var videotype = $(this).attr('data-videotype');

		
		switch(videotype){
			case 'brightcove':
				var theid = $(this).find('*[id^="myExperience"]').attr('id');
				
				setTimeout("firebcplayer('"+theid+"')",1250);
				//alert(theid);
			break;
			case 'youtube':
				//alert('x')
				//var player = $(this).find('embed,object').addClass('latestopenedytplayer');				
				//
				//setTimeout("playlatestytvid",1250);
				
				//player.playVideo():
			break;
			default:
			
			break;
		
		}
		
		
	});
	
});

var latestopenedytplayer;	


//function playlatestytvid(){
//	var player= $('.latestopenedytplayer').removeClass('latestopenedytplayer').get(0)
//	latestopenedytplayer.playVideo();
//}

function firebcplayer(id){
	var player = brightcove.getExperience(id);
	var videoPlayer = player.getModule(APIModules.VIDEO_PLAYER);
	videoPlayer.pause(false);
}
