
// Category / Subcategory expanding list
window.addEvent('domready', function() {

	// Only check once per day irrespective of whether a campaign is set
	if(!Cookie.read('ProtalkMemberCampaign')){
		// If we havent checked today, see if a campaign in running
		var campReq = new Request.JSON({
		   url: '/ajaxHandler.php',
		   data: {
			   Site: 'egtalk',
			   Method: 'checkForCampaignMessage'
		   },
		   onSuccess: function(response){
			   if(response.id){
				   // If there is a campaign set up see if this user has already been asked
				   if(!Cookie.read(response.cookiename)){
					   // Wait delay number of seconds
					   setTimeout(function(){
						   var size = window.getSize();
						   var col = $('header').getStyle('background-color');
						   var breadCol = $('navigation').getStyle('background-color');

						   // Create and show the window
						   var El = new Element('div',{
									   'id': 'campaigndiv',
								   styles: {
									   'opacity' : 0,
									   'z-order' : 199,
									   'background-color': '#ffffff',
									   'width': response.width + 'px',
									   'border' : 'thick ' + col + ' solid',
									   'position': 'absolute',
									   'margin' : '3px',
									   'left': response.left ? response.left : ( (size.x/2) - (response.width/2)) + 'px',
									   'top': response.top ? response.top : ( (size.y/2) - (response.height/2)) + 'px'
								   }
						   }).inject('content','top');

						   var contents = '';

						   contents += '<h3 id="camtitle" class="highlight" style="cursor: hand; padding: 3px; text-align: center;"  >' + response.name + '</h3>';
						   contents += '<div style="width: 100%; overflow: auto; ">';
						   contents += '<iframe src="' + response.contents + '" style="width: 100%; height: ' + response.height + 'px;" scrolling="no" id="camiframe" ></iframe>';

						   contents += '</div>';

						   contents += '<div id="camfoot" style="text-align: right;">';
						   contents += '<a href="javascript:closecampaign()">'; //margin-left:' + (response.width * 0.8) + 'px;">';
						   contents += '<span style="font-size: 14px; font-family: arial; padding: 6px;">Close</span></a></div>';

						   $('campaigndiv').makeDraggable();

						   $('campaigndiv').innerHTML = contents;

						   $('camiframe').addEvent('load',function() {
							   $('campaigndiv').setStyle('width',$('camiframe').getSize().x);
							   $('campaigndiv').setStyle('height',$('camiframe').getSize().y + $('camtitle').getSize().y + $('camfoot').getSize().y);
						   });

						   $('campaigndiv').set('tween',{duration:response.fadetime ? response.fadetime * 1000 : 1000});
						   $('campaigndiv').tween('opacity',1.0);

						   // Write the cookie for this campaign
						   if(response.writecookie == 'yes'){
							   Cookie.write(response.cookiename,'asked',{duration: response.cookieduration, path: '/' });
						   }
					   },response.delay * 1000);
				   }
			   }
		   }
	   }).send();

		// Set the cookie so this is only done once per day
		Cookie.write('ProtalkMemberCampaign','checked',{duration:1});
	}



	var catListAccordian = new Accordion($$('.toggler'), $$('.element'), {
		start:'all-closed',
		opacity: false,
		alwaysHide: true
	});

	
		
});

function closecampaign(){

	$('campaigndiv').tween('opacity',0).chain(function(){
		$('campaigndiv').dispose()
	})
}


var curTab = '1';

function openTab(tab){
	$('tabContent'+curTab).setStyle('display','none');
	$('tabContent'+tab).setStyle('display','block');

	$('tab'+curTab).removeClass('active');
	$('tab'+tab).addClass('active');
	curTab = tab;
}


