/*
Final.Widgets.js - The JS script that has all the widgets specific js.
--
Written by Ivik Injerd, Dave Sienkowski
Dependedcies:
---->Jquery
---->Jquery UI
---->Final.js
*/

$(document).ready(function(){
	
	// Webnote Auto Submit
	$("#webnote #note").change(function(){
		$(this).submit();
	});								
	// End Webnote Auto Submit
	
	// Breaking News Accordian
	//$("#breaknewswidget").accordion({
	//	collapsible: true,
	//	autoHeight: false,
	//	icons: { 'header': 'ui-icon-notice', 'headerSelected': 'ui-icon-minus' },
	//	active: false
	//});
	// End Breaking News Accordian

	// Browser
	$('.w-browser-print').live('click',function(e){
		var bnid = $(this).parents('.nde-window').find('iframe').get(0);
		bnid.focus();
		print();
		e.preventDefault();
	});
	// End Browser
	
	//Guardian alarm window popup
	$('.guardalarm a').live('click',function(e){
		var go = $(this).attr('href');
		$(document).xmodal({
			title:'Guardian Alarm',
			html:'<iframe width="100%" height="600" frameborder="0" src="'+go+'"></iframe>',
			width:800,
			height:630,
			speed:0.2
		});
		e.preventDefault();
	});
	// End Guardian alarm window popup
	
	//Crimewatch window popups
	$('#cw_add').click(function(e){
		dumont.doRequest({uid:dumont.uid,action:'crimewatch/post'},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Post A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.cw_edit').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'crimewatch/edit',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Edit A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.cw_anonview').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'crimewatch/anon/anonview',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Anonymous Tip',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	// End Crimewatch window popups
	
	//Sheriff Mac window popups
	$('.sm_add').click(function(e){
		dumont.doRequest({uid:dumont.uid,action:'sheriffmac/post'},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Post A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.sm_edit').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'sheriffmac/edit',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Edit A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.sm_anonview').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'sheriffmac/anon/anonview',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Anonymous Tip',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	// End Sheriff Mac window popups
	
	//Eastpointe CW window popups
	$('#ec_add').click(function(e){
		dumont.doRequest({uid:dumont.uid,action:'eastpointecw/post'},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Post A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.ec_edit').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'eastpointecw/edit',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Edit A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.ec_anonview').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'eastpointecw/anon/anonview',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Anonymous Tip',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	// End Eastpointe CW window popups
	
	//New Baltimore CW window popups
	$('#nbc_add').click(function(e){
		dumont.doRequest({uid:dumont.uid,action:'newbaltimorecw/post'},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Post A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.nbc_edit').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'newbaltimorecw/edit',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Edit A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.nbc_anonview').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'newbaltimorecw/anon/anonview',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Anonymous Tip',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	// End New Baltimore CW window popups
	
	//Grosse Pointe CW window popups
	$('#gpc_add').click(function(e){
		dumont.doRequest({uid:dumont.uid,action:'grossepointecw/post'},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Post A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.gpc_edit').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'grossepointecw/edit',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Edit A.P.B',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	$('.gpc_anonview').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'grossepointecw/anon/anonview',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Anonymous Tip',html:reply.content,width:700,height:450,anim:false});
		});
		e.preventDefault();
	});
	// End Grosse Pointe CW window popups
	
	// Adds a new contact to the user contact widget, then displays result	
	$('span.contactSettings').live('click', function(e){
		
		var otherUserBreaks = $(this).find('a').attr('href');
		var splits = otherUserBreaks.split('/');
		var otherUser = splits.pop();
		var actionVar = splits.pop();
		
		$(this).fadeOut(200, function()
		{
			dumont.doRequest({domobj:this,uid:dumont.uid,otheruser:otherUser,action:'user/'+actionVar},function(reply){
				var textResult = '';
				
				if (actionVar == 'setcontact')
					textResult = reply.content == '1' ? 'Contact Added' : 'Error adding contact';
				else if (actionVar == 'removecontact')
					textResult = reply.content == '1' ? 'Contact Removed' : 'Error removing contact';
				else
					textResult = 'Unknown action: '+actionVar;
					
				$(this.data.domobj).text(textResult).fadeIn(200);
				debugWin(reply,true,'#ff0');
				debugWin(this,true,'#f0f');
			});
		});
		e.preventDefault();
	});
	// End new contact to user contact widget
	
	// Adjust the calendar colors on hover
	$('.w-calendar .content td.clickable').live('mouseover', function(e){
		$(this).css("background-color","white");
		$(this).css("cursor","pointer");
	});
	
	$('.w-calendar .content td.clickable').live('mouseout', function(e){
		$(this).css("background-color","");
	});
	$('.w-calendar .calendardd').live('change',function(e){
		var gid = $(this).val();
		var wik = getWIK(this);
		var tik = getTIK();
		dumont.doRequest({wik:wik,tik:tik,action:'calendar/show',group:gid,ajax_link:true},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$('.wik-'+wik+' .nde-wrefresh').click();
		});
		
	});
	// End adjust calender colors on hover
	
	//CrimeWatch Tab show/hide content
	//Set the initial state: highlight the first button...
	$('#cw_alerts_jtabs').find('li:eq(0)').addClass('selected');
	//and hide all slides except the first one
	$('.cw_alerts_middle').find('> div:eq(0)').nextAll().hide();
	//actions that apply on click of any of the buttons
	$('#cw_alerts_jtabs li').live('click', function(event) {
		//turn off the link so it doesn't try to jump down the page
		event.preventDefault();
		//un-highlight the buttons
		$('#cw_alerts_jtabs li').removeClass();
		//hide all the slides
		$('.cw_alerts_middle > div').hide();
		//highlight the current button
		$(this).addClass('selected');
		//get the index of the current button...
		var index = $('#cw_alerts_jtabs li').index(this);
		//and use that index to show the corresponding slide
		$('.cw_alerts_middle > div:eq('+index+')').show();
	});
	// End CrimeWatch Tab show/hide content
	
	//CrimeWatch event show mssg
	$('.cw_event_mssg_body').live('hide',function(e){
		e.preventDefault();
	});
	$('.cw_event').live('click',(function(e){
		var bnid = $(this).attr('id');
		$('#'+bnid+'_mssg_title, #'+bnid+'_mssg_body').toggle(100);
		e.preventDefault();
		})
	);
	// End CrimeWatch event show mssg
	
	//CrimeWatch Attachments popup
	$('.cw_attachment a').live('click',function(e){
		var go = $(this).attr('href');
		$(document).xmodal({title:'Attachment',image:go,type:'image'});
		e.preventDefault();
	});
	// End CrimeWatch Attachments popup
	
	//CrimeWatch Pagination
	$('.cw_paginator a').live('click', function(e) {
		var go = $(this).attr('href');
		var content = $(this).parents('.cw_content');
		var page = $(this).attr('href').split('/').pop();
		content.fadeOut(500,function(){
			dumont.doRequest({uid:dumont.uid,action:'crimewatch/page',page:page}, function(reply) {
				debugWin(reply, false, '#ff0');
				debugWin(this, false, '#f0f');
				content.html(reply.content).fadeIn(500);
			});
		});
		e.preventDefault();
	});
	// End Crimewatch Pagination
	
	//SheriffMac Tab show/hide content
	//Set the initial state: highlight the first button...
	$('#sm_alerts_jtabs').find('li:eq(0)').addClass('selected');
	//and hide all slides except the first one
	$('.sm_alerts_middle').find('> div:eq(0)').nextAll().hide();
	//actions that apply on click of any of the buttons
	$('#sm_alerts_jtabs li').live('click', function(event) {
		//turn off the link so it doesn't try to jump down the page
		event.preventDefault();
		//un-highlight the buttons
		$('#sm_alerts_jtabs li').removeClass();
		//hide all the slides
		$('.sm_alerts_middle > div').hide();
		//highlight the current button
		$(this).addClass('selected');
		//get the index of the current button...
		var index = $('#sm_alerts_jtabs li').index(this);
		//and use that index to show the corresponding slide
		$('.sm_alerts_middle > div:eq('+index+')').show();
	});
	// End SheriffMac Tab show/hide content
	
	//SheriffMac event show mssg
	$('.sm_event_mssg_body').live('hide',function(e){
		e.preventDefault();
	});
	$('.sm_event').live('click',(function(e){
		var bnid = $(this).attr('id');
		$('#'+bnid+'_mssg_title, #'+bnid+'_mssg_body').toggle(100);
		e.preventDefault();
		})
	);
	//End SheriffMac event show mssg
	
	//SheriffMac Attachments popup
	$('.sm_attachment a').live('click',function(e){
		var go = $(this).attr('href');
		$(document).xmodal({title:'Attachment',image:go,type:'image'});
		e.preventDefault();
	});
	//END SheriffMac Attachments popup
	
	//SheriffMac Pagination
	$('.sm_paginator a').live('click', function(e) {
		var go = $(this).attr('href');
		var content = $(this).parents('.sm_content');
		var page = $(this).attr('href').split('/').pop();
		content.fadeOut(500,function(){
			dumont.doRequest({uid:dumont.uid,action:'sheriffmac/page',page:page}, function(reply) {
				debugWin(reply, false, '#ff0');
				debugWin(this, false, '#f0f');
				content.html(reply.content).fadeIn(500);
			});
		});
		e.preventDefault();
	});
	//End SheriffMac Pagination
	
	//EastpointeCW Tab show/hide content
	//Set the initial state: highlight the first button...
	$('#ec_alerts_jtabs').find('li:eq(0)').addClass('selected');
	//and hide all slides except the first one
	$('.ec_alerts_middle').find('> div:eq(0)').nextAll().hide();
	//actions that apply on click of any of the buttons
	$('#ec_alerts_jtabs li').live('click', function(event) {
		//turn off the link so it doesn't try to jump down the page
		event.preventDefault();
		//un-highlight the buttons
		$('#ec_alerts_jtabs li').removeClass();
		//hide all the slides
		$('.ec_alerts_middle > div').hide();
		//highlight the current button
		$(this).addClass('selected');
		//get the index of the current button...
		var index = $('#ec_alerts_jtabs li').index(this);
		//and use that index to show the corresponding slide
		$('.ec_alerts_middle > div:eq('+index+')').show();
	});
	// End EastpointeCW Tab show/hide content
	
	//EastpointeCW event show mssg
	$('.ec_event_mssg_body').live('hide',function(e){
		e.preventDefault();
	});
	$('.ec_event').live('click',(function(e){
		var bnid = $(this).attr('id');
		$('#'+bnid+'_mssg_title, #'+bnid+'_mssg_body').toggle(100);
		e.preventDefault();
		})
	);
	//End EastpointeCW event show mssg
	
	//EastpointeCW Attachments popup
	$('.ec_attachment a').live('click',function(e){
		var go = $(this).attr('href');
		$(document).xmodal({title:'Attachment',image:go,type:'image'});
		e.preventDefault();
	});
	//END EastpointeCW Attachments popup
	
	//EastpointeCW Pagination
	$('.ec_paginator a').live('click', function(e) {
		var go = $(this).attr('href');
		var content = $(this).parents('.ec_content');
		var page = $(this).attr('href').split('/').pop();
		content.fadeOut(500,function(){
			dumont.doRequest({uid:dumont.uid,action:'sheriffmac/page',page:page}, function(reply) {
				debugWin(reply, false, '#ff0');
				debugWin(this, false, '#f0f');
				content.html(reply.content).fadeIn(500);
			});
		});
		e.preventDefault();
	});
	//End EastpointeCW Pagination
	
	// Sweepstakes widget
	$('.w-sweepstakes a.sweeps-edit').click(function(e){
		var editid = $(this).attr('href').split('/').pop();
		dumont.doRequest({uid:dumont.uid,action:'sweepstakes/edit',editid:editid},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$(document).xmodal({title:'Edit',html:reply.content,width:320,height:240,anim:false});
		});
		e.preventDefault();
	});
	// End Sweepstakes widget
	
	// Contractor widget
	$('.w-contractor .contractor-search input').live('keyup change',function(){
		if ((
			$(this).parents('form').find('input#city1').val().length ||
			$(this).parents('form').find('input#city2').val().length ||
			$(this).parents('form').find('input#city3').val().length
			) && (
			$(this).parents('form').find('input#service_type-1').is(':checked') ||
			$(this).parents('form').find('input#service_type-2').is(':checked')
			))
			$(this).parents('form').find('#submit').attr('disabled','');
		else
			$(this).parents('form').find('#submit').attr('disabled','disabled');
	});
	$('.w-contractor .contractor-search form').live('submit',function(e){
		var city1 = $(this).find('input#city1').val();
		var city2 = $(this).find('input#city2').val();
		var city3 = $(this).find('input#city3').val();
		var service_type = ($(this).find('input#service_type-1').is(':checked')?1:0)+($(this).find('input#service_type-2').is(':checked')?2:0);
		var wik = getWIK(this);
		$('.w-contractor.wik-'+wik+' .contractor-cat-form:visible, .w-contractor.wik-'+wik+' .contractor-cat-head:visible, .w-contractor.wik-'+wik+' .contractor-con-form:visible, .w-contractor.wik-'+wik+' .contractor-con-head:visible').slideUp(300);
		if (city1.length || city2.length || city3.length){
			dumont.doRequest({wik:getWIK(this),action:'contractor/getcats',city1:city1,city2:city2,city3:city3,service_type:service_type},function(reply){
				debugWin(reply,false,'#ff0');
				debugWin(this,false,'#f0f');
				var cats = reply.content.split(',');
				$('.w-contractor.wik-'+wik+' .contractor-cat-form').find('#parent_wt-element label').hide();
				$('.w-contractor.wik-'+wik+' .contractor-cat-form').find('#worktypes-element label').hide().removeClass('enabled');
				for (i in cats){
					$('.w-contractor.wik-'+wik+' .contractor-cat-form').find('#parent_wt-element label[for='+wik+'-parent_wt-'+cats[i]+']').show();
					$('.w-contractor.wik-'+wik+' .contractor-cat-form').find('#worktypes-element label[for='+wik+'-worktypes-'+cats[i]+']').addClass('enabled');
				}
				$('.w-contractor.wik-'+wik+' .contractor-cat-form').find('#parent_wt-element input').attr('checked','');
				$('.w-contractor.wik-'+wik+' .contractor-cat-form').find('#parent_wt-element label').removeClass('selected');
				$('.w-contractor.wik-'+wik+' .contractor-cat-form, .w-contractor.wik-'+wik+' .contractor-cat-head').slideDown(300);
				$('.w-contractor.wik-'+wik+' .contractor-con-form form').find('input#parent_wt, input#worktypes').val('');
				$('.w-contractor.wik-'+wik+' .contractor-cat-form').find('#worktypes-element:not(:has(.note))').prepend('<p class="notehd">Click any category to begin! </p><p class="note">You can receive referalls for one category at a time. Select any amount of desired work types within a given work category.</p>');
			});
			$('.w-contractor.wik-'+wik+' .contractor-con-form form').find('input#city1').val(city1);
			$('.w-contractor.wik-'+wik+' .contractor-con-form form').find('input#city2').val(city2);
			$('.w-contractor.wik-'+wik+' .contractor-con-form form').find('input#city3').val(city3);
			$('.w-contractor.wik-'+wik+' .contractor-con-form form').find('input#service_type').val(service_type);
		}
		e.preventDefault();
	});
	$('.w-contractor .contractor-cat-form #worktypes-element label').hide();
	$('.w-contractor .contractor-cat-form #parent_wt-element label').live('click',function(e){
		var wik = getWIK(this);
		$('.w-contractor.wik-'+wik+' .contractor-cat-form #worktypes-element .notehd').slideUp(300,function(){ $(this).remove(); });
		$('.w-contractor.wik-'+wik+' .contractor-cat-form #worktypes-element .note').slideUp(300,function(){ $(this).remove(); });
		$(this).addClass('selected').find('input').attr('checked','checked');
		$(this).prevAll().removeClass('selected').find('input').attr('checked','');
		$(this).nextAll().removeClass('selected').find('input').attr('checked','');
		$(this).parent().parent().find('#worktypes-element label').hide();
		if (typeof contractor_cats != 'undefined'){
			var cc = contractor_cats[$(this).find('input').val()];
			for (var i in cc){
				$(this).parent().parent().find('#worktypes-element label.enabled:has(input#'+wik+'-worktypes-'+cc[i]+')').show();
			}
		}
		$('.w-contractor.wik-'+wik+' .contractor-con-form form input#worktypes').val('');
		$('.w-contractor.wik-'+wik+' .contractor-con-form form input#parent_wt').val($(this).find('input').val());
		var wt = [];
		var typeschecked = function(){
			wt.push($(this).val());
		}
		$('.w-contractor.wik-'+wik+' .contractor-cat-form #worktypes-element input:visible:checked').each(typeschecked);
		if (wt.length == 0){
			$('.w-contractor.wik-'+wik+' .contractor-con-form, .w-contractor.wik-'+wik+' .contractor-con-head').slideUp(300);
		}else{
			$('.w-contractor.wik-'+wik+' .contractor-con-form:hidden, .w-contractor.wik-'+wik+' .contractor-con-head:hidden').slideDown(300);
		}
		e.preventDefault();
	});
	var labelwastarget = false;
	$('.w-contractor .contractor-cat-form #worktypes-element input').live('change',function(e){
		var wik = getWIK(this);
		var wt = [];
		var typeschecked = function(){
			wt.push($(this).val());
		}
		$(this).parent().prevAll().find('input:visible:checked').each(typeschecked);
		$(this).parent().nextAll().find('input:visible:checked').each(typeschecked);
		if ($(this).is(':checked')) wt.push($(this).val());
		//alert(wt.join(','));
		$('.w-contractor.wik-'+wik+' .contractor-con-form form input#worktypes').val(wt.join(','));
		if (wt.length == 0){
			$('.w-contractor.wik-'+wik+' .contractor-con-form, .w-contractor.wik-'+wik+' .contractor-con-head').slideUp(300);
		}else{
			$('.w-contractor.wik-'+wik+' .contractor-con-form:hidden, .w-contractor.wik-'+wik+' .contractor-con-head:hidden').slideDown(300);
		}
	});
	// End Contractor widget
	
	//Begin NewbaltimoreCW
	//NewbaltimoreCW Tab show/hide content
	//Set the initial state: highlight the first button...
	$('#nbc_alerts_jtabs').find('li:eq(0)').addClass('selected');
	//and hide all slides except the first one
	$('.nbc_alerts_middle').find('> div:eq(0)').nextAll().hide();
	//actions that apply on click of any of the buttons
	$('#nbc_alerts_jtabs li').live('click', function(event) {
		//turn off the link so it doesn't try to jump down the page
		event.preventDefault();
		//un-highlight the buttons
		$('#nbc_alerts_jtabs li').removeClass();
		//hide all the slides
		$('.nbc_alerts_middle > div').hide();
		//highlight the current button
		$(this).addClass('selected');
		//get the index of the current button...
		var index = $('#nbc_alerts_jtabs li').index(this);
		//and use that index to show the corresponding slide
		$('.nbc_alerts_middle > div:eq('+index+')').show();
	});
	// End NewbaltimoreCW Tab show/hide content
	
	//NewbaltimoreCW event show mssg
	$('.nbc_event_mssg_body').live('hide',function(e){
		e.preventDefault();
	});
	$('.nbc_event').live('click',(function(e){
		var bnid = $(this).attr('id');
		$('#'+bnid+'_mssg_title, #'+bnid+'_mssg_body').toggle(100);
		e.preventDefault();
		})
	);
	//End NewbaltimoreCW event show mssg
	
	//NewbaltimoreCW Attachments popup
	$('.nbc_attachment a').live('click',function(e){
		var go = $(this).attr('href');
		$(document).xmodal({title:'Attachment',image:go,type:'image'});
		e.preventDefault();
	});
	//END NewbaltimoreCW Attachments popup
	
	//NewbaltimoreCW Pagination
	$('.nbc_paginator a').live('click', function(e) {
		var go = $(this).attr('href');
		var content = $(this).parents('.nbc_content');
		var page = $(this).attr('href').split('/').pop();
		content.fadeOut(500,function(){
			dumont.doRequest({uid:dumont.uid,action:'newbaltimorecw/page',page:page}, function(reply) {
				debugWin(reply, false, '#ff0');
				debugWin(this, false, '#f0f');
				content.html(reply.content).fadeIn(500);
			});
		});
		e.preventDefault();
	});
	//End NewbaltimoreCW Pagination
	//End NewbaltimoreCW
	
	//Begin GrossepointeCW
	//GrossepointeCW Tab show/hide content
	//Set the initial state: highlight the first button...
	$('#gpc_alerts_jtabs').find('li:eq(0)').addClass('selected');
	//and hide all slides except the first one
	$('.gpc_alerts_middle').find('> div:eq(0)').nextAll().hide();
	//actions that apply on click of any of the buttons
	$('#gpc_alerts_jtabs li').live('click', function(event) {
		//turn off the link so it doesn't try to jump down the page
		event.preventDefault();
		//un-highlight the buttons
		$('#gpc_alerts_jtabs li').removeClass();
		//hide all the slides
		$('.gpc_alerts_middle > div').hide();
		//highlight the current button
		$(this).addClass('selected');
		//get the index of the current button...
		var index = $('#gpc_alerts_jtabs li').index(this);
		//and use that index to show the corresponding slide
		$('.gpc_alerts_middle > div:eq('+index+')').show();
	});
	// End GrossepointeCW Tab show/hide content
	
	//GrossepointeCW event show mssg
	$('.gpc_event_mssg_body').live('hide',function(e){
		e.preventDefault();
	});
	$('.gpc_event').live('click',(function(e){
		var bnid = $(this).attr('id');
		$('#'+bnid+'_mssg_title, #'+bnid+'_mssg_body').toggle(100);
		e.preventDefault();
		})
	);
	//End GrossepointeCW event show mssg
	
	//GrossepointeCW Attachments popup
	$('.gpc_attachment a').live('click',function(e){
		var go = $(this).attr('href');
		$(document).xmodal({title:'Attachment',image:go,type:'image'});
		e.preventDefault();
	});
	//END GrossepointeCW Attachments popup
	
	//GrossepointeCW Pagination
	$('.gpc_paginator a').live('click', function(e) {
		var go = $(this).attr('href');
		var content = $(this).parents('.gpc_content');
		var page = $(this).attr('href').split('/').pop();
		content.fadeOut(500,function(){
			dumont.doRequest({uid:dumont.uid,action:'grossepointecw/page',page:page}, function(reply) {
				debugWin(reply, false, '#ff0');
				debugWin(this, false, '#f0f');
				content.html(reply.content).fadeIn(500);
			});
		});
		e.preventDefault();
	});
	//End GrossepointeCW Pagination
	//End GrossepointeCW
	
	// Fileshare widget
	$('.w-fileshare .dir a.name').live('click',function(e){
		var parts = $(this).attr('href').split('/');
		var file = parts.pop();
		var type = parts.pop();
		//debug_mode = true;
		dumont.doRequest({wik:getWIK(this),action:'fileshare/open',file:file,type:type},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$('.wik-'+this.data.wik+' .nde-wrefresh').click();
		});
		
		e.preventDefault();
	});
	$('.w-fileshare .file-listing a.delete').live('click',function(e){
		var parts = $(this).attr('href').split('/');
		var file = unescape(parts.pop());
		var type = parts.pop();
		var li = $(this).parents('li');
		var wik = getWIK(this);
		li.fadeTo(300,0.5);
		//debug_mode = true;
		$(document).xmodal({
			title:'Delete '+(type=='d'?'Directory':'File'),
			html:'Are you sure you want to delete this '+(type=='d'?'directory':'file')+'?',
			type:'confirm',
			width:350,
			height:130,
			callback:function(ret){
				if (ret){
					dumont.doRequest({wik:wik,action:'fileshare/delete',file:file,type:type},function(reply){
						debugWin(reply,false,'#ff0');
						debugWin(this,false,'#f0f');
						if (reply.content){
							li.slideUp(300,function(){
								$(this).remove();
							});
						}else{
							$(document).xmodal({
								title:'Failed to Delete',
								html:'<p>Error: This '+(type=='d'?'directory':'file')+' could not be deleted.'+(type=='d'?'<br />Please make sure this directory is empty and try again.':'')+'</p><p>Please contact support if this issue persists.</p>',
								type:'alert'
							});
							li.fadeTo(300,1);
						}
					});
				}else{
					li.fadeTo(300,1);
				}
			}
		});
		e.preventDefault();
	});
	//$('.w-fileshare .upload-sect,.w-fileshare .dir-sect').hide();
	$('.w-fileshare .upload').live('click',function(e){
		$(this).parent().parent().find('.dir-sect:visible').slideUp(500);
		$(this).parent().parent().find('.upload-sect').slideToggle(500);
		e.preventDefault();
	});
	$('.w-fileshare .create-dir').live('click',function(e){
		$(this).parent().parent().find('.upload-sect:visible').slideUp(500);
		$(this).parent().parent().find('.dir-sect').slideToggle(500);
		e.preventDefault();
	});
	$('.w-fileshare .upload-sect form').live('submit',function(e){
		var upload_sect = $(this).parent();
		var submit_btn = $(this).find('input[type=submit]').attr('disabled','disabled');
		var wik = getWIK(this);
		$(upload_sect).append('<iframe name="'+wik+'_uploadframe" id="'+wik+'-uploadframe" width="0" height="0" style="border:0;position:absolute;"></iframe>');
		$('#'+wik+'-uploadframe').load(function(){
				var upload_res = $(this).contents().find('.upload-result').html();
				if(upload_res == 'Uploaded'){
					$('.wik-'+wik+' .nde-wrefresh').click();					
				}else{
					$(document).xmodal({
						title:'Failed to Upload',
						html:'<p>Error: This file could not be uploaded.<br/>The file you tried to upload will exceed your maximum storage quota.</p><p>Please contact support if you\'d like to increase your storage quota.</p>',
						type:'alert',
						height:220,
						callback:function(){
							$('#'+wik+'-uploadframe').remove();
							submit_btn.attr('disabled','');
						}
					});
				}
		}).appendTo(upload_sect);
		$(this).attr('target',wik+'_uploadframe');
	});
	$('.w-fileshare .share-options').live('click',function(e){
		var wik = getWIK(this);
		dumont.doRequest({wik:wik,action:'fileshare/shareoptions'},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$('.wik-'+wik+' .nde-wrefresh').click();
		});
		e.preventDefault();
	});
	$('.w-fileshare .file-listing a.share').live('click',function(e){
		var wik = getWIK(this);
		var file = unescape($(this).attr('href').split('/').pop());
		dumont.doRequest({wik:wik,action:'fileshare/share',share:file},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$('.wik-'+wik+' .nde-wrefresh').click();
		});
		e.preventDefault();
	});
	$('.w-fileshare .share-sect form select#share_type').live('change',function(){
		if ($(this).val() == 'group'){
			$(this).parents('form').find('dd#share_group-element').show();
		}else{
			$(this).parents('form').find('dd#share_group-element').hide();
		}
		if ($(this).val() == 'user'){
			$(this).parents('form').find('dd#share_user-element').show();
		}else{
			$(this).parents('form').find('dd#share_user-element').hide();
		}
	});
	$('.w-fileshare .share-sect form button#share_add').live('click',function(e){
		var wik = getWIK(this);
		if (!$(this).parents('form').find('dd#share_list-element ul').length){
			$(this).parents('form').find('dd#share_list-element').append('<ul></ul>');
		}
		var listel = $(this).parents('form').find('dd#share_list-element ul');
		var type = $(this).parents('form').find('select#share_type').val();
		if (type == 'group'){
			var groupel = $(this).parents('form').find('select#share_group option:selected').attr('disabled','disabled');
			var val = groupel.parent().val();
			var val2 = groupel.text();
			var groupval = groupel.siblings(':enabled:first').val();
			if(groupval){
				$(this).parents('form').find('select#share_group').val(groupval);
			}else {
				$(this).parents('form').find('select#share_type option[value=group]').attr('disabled','disabled').parent().val('user').change();
			}
		}else if (type == 'user'){
			var val = $(this).parents('form').find('input#share_user').val();
			$(this).parents('form').find('input#share_user').val('');
		}else{
			$(this).parents('form').find('select#share_type option:selected').attr('disabled','disabled').parent().val('user').change();
			var val = 'ON';
		}
		listel.append('<li class="share-'+type+'"><span class="val">'+type+':'+escape(val)+'</span><a href="#remove-share"><img src="'+iotower_base_url+'/images/fileshare/delete16.png" alt="Remove" /></a>'+type+': '+(val2?val2:val)+'</li>');
		var hidden = $(this).parents('form').find('input#share_list');
		var hiddenval = [];
		listel.find('li').each(function(){
			hiddenval.push($(this).find('span.val').text());
		});
		hidden.val(hiddenval.join(','));
		e.preventDefault();
	});
	$('.w-fileshare .share-sect form dd#share_list-element ul li a').live('click',function(e){
		$(this).parent().slideUp(300,function(){
			var listel = $(this).parents('form').find('dd#share_list-element ul');
			var hidden = $(this).parents('form').find('input#share_list');
			var item = $(this).find('span.val').text().split(':');
			if(item[0].toUpperCase() == 'ALL'){
				$(this).parents('form').find('select#share_type option[value=all]').attr('disabled','');
			}
			else if(item[0].toUpperCase() == 'SITE'){
				$(this).parents('form').find('select#share_type option[value=site]').attr('disabled','');
			}
			else if(item[0].toUpperCase() == 'GROUP'){
				var grouprem = $(this).parents('form').find('select#share_group option[value="'+unescape(item[1])+'"]').attr('disabled','');
				if(grouprem.siblings(':enabled').length == 0){
					grouprem.parent().val(grouprem.val());
				}
				$(this).parents('form').find('select#share_type option[value=group]').attr('disabled','');
			}
			$(this).remove();
			var hiddenval = [];
			listel.find('li').each(function(){
				hiddenval.push($(this).find('span.val').text());
			});
			hidden.val(hiddenval.join(','));
		});
		e.preventDefault();
	});
	// End fileshare widget
	// Begin Groups Widget
	$('.w-groups .groupdd').live('change',function(e){
		var gid = $(this).val();
		var wik = getWIK(this);
		var tik = getTIK();
		dumont.doRequest({wik:wik,tik:tik,action:'groups/show',group:gid,ajax_link:true},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$('.wik-'+wik+' .nde-wrefresh').click();
		});
		
	});
	
	$('.w-groups .show-groupnews li').live('click',function(e){
		$(this).find('p').slideToggle(200);
		e.preventDefault();
	});
	$('.w-groups h3').live('click',function(e){
		var expd = this.className.replace(/^.*\b(\w+_expd).*$/,'$1');
		$(this).toggleClass('expanded').next().slideToggle(200,function(){
			var expdv = $(this).is(':visible');
			var wik = getWIK(this);
			var tik = getTIK();
			dumont.doRequest({wik:wik,tik:tik,action:'groups/expd',expd_name:expd,expd_val:expdv,ajax_link:true},function(reply){
				debugWin(reply,false,'#ff0');
				debugWin(this,false,'#f0f');
			});
		});
		e.preventDefault();
	});
	$('div.inline-addwidget a').live('click',function(e){
		var wname = $(this).attr('href').split('/').pop();
		$('#all-widgets a[href$="/'+wname+'"]').click();
		e.preventDefault();
	});
	// End Groups Widget
	// Begin Shoutbox Widget
	$('.w-shoutbox dl dd').live('mouseenter',function(e){
		$(this).find('.control').stop(true,true).fadeIn(200);
	}).live('mouseleave',function(){
		$(this).find('.control').stop(true,true).fadeOut(200);
	});
	$('.w-shoutbox .shoutboxdd').live('change',function(e){
		var gid = $(this).val();
		var wik = getWIK(this);
		var tik = getTIK();
		dumont.doRequest({wik:wik,tik:tik,action:'shoutbox/show',group:gid,ajax_link:true},function(reply){
			debugWin(reply,false,'#ff0');
			debugWin(this,false,'#f0f');
			$('.wik-'+wik+' .nde-wrefresh').click();
		});
		
	});
	// End Shoutbox Widget
});

