
var Rules = {
	'.flash_message' : function(el) {
		new Effect.Highlight(el, {startcolor:'#CCD4DD', endcolor:'#FFFFFF', duration: 4.0});
	},
	'.form_input' : function(el) {
		el.onfocus = function() {
			try {
				$(el.id + "Hint").style.zIndex = 600;
				$(el.id + "Hint").style.position = 'absolute';
				$(el.id + "Hint").style.display = 'block';
			}
			catch (err) { }
		}
		el.onblur = function() {
			try {
				$(el.id + "Hint").style.display = 'none';
			}
			catch (err) { }			
		}
	},
	'.topic_subject' : function(el) {
		if (el.value == '') {
			el.style.color = '#999999';
			el.value = 'Enter A Subject';
		}
		else {
			postSubject = false;	
		}
		el.onfocus = function() {
			if (postSubject) {
				el.value = '';
				el.style.color = '#000000';
				postSubject = false;
			}
		}
	},
	'h3#edit_title' : function(el) {
		new Ajax.InPlaceEditor(el,'/design/save/title/',{ okText:'Save', highlightcolor:'#BDD6E8', formClassName:'design_inplace_edit' });	
	},
	'h4#edit_tagline' : function(el) {
		new Ajax.InPlaceEditor(el,'/design/save/tagline/',{ okText:'Save', highlightcolor:'#BDD6E8', formClassName:'design_inplace_edit' });	
	},
	'a.select_photo' : function(el) {
		el.onclick = function(ev) {
			objectID = 0;
			objectID = getID(el.id);
			
			
			var elementList = document.getElementsByClassName("select_photo");
			var elCount = elementList.length;
			for (i = 0; i < elCount; i++) {
				elementList[i].style.border = '1px solid #CCCCCC';
				elementList[i].style.padding = '2px';
				
				$("photoselect_" + getID(elementList[i].id)).checked = false;
			}
			
			
			$("photoselect_" + objectID).checked = true;
			el.style.border = '3px solid #1281D7';
			el.style.padding = '0px';
			$('ok_button').disabled = false;
			
			return false;
		}
		
	},
	'.post_list li:click' : function(el) {
		alert('test');
		el.style.backgroundColor = '#555555';	
	}
}



Behaviour.register(Rules);


var postSubject = true;


function getID(inid) {
	if (inid.lastIndexOf('_') != -1) {
		return inid.substring(inid.lastIndexOf('_') + 1);
	}
	return false;
}

function classDisplay(class_name, display_property) {
	var elementList = document.getElementsByClassName(class_name);
	var elCount = elementList.length;
	for (i = 0; i < elCount; i++) {
		elementList[i].style.display = display_property;
	}
	return false;
}
function classToggle(class_name) {
	var elementList = document.getElementsByClassName(class_name);
	var elCount = elementList.length;
	
	if (elCount > 0) {
		if (elementList[0].style.display == 'none') {
			classDisplay(class_name, '');
		}
		else {
			classDisplay(class_name, 'none');
		}
	}
	return false;
}

function goTo(new_location) {
	window.location.href = new_location;
	return false;
}


var modal_ajax = function(display_message, url) {
	m = Control.Modal.current;
	if (m == false) {
		m = new Control.Modal(false);
	}
	
	display_message = '<div class="modal_loading">' + display_message + '</div>';
	
	m.initialize(false,{
		contents: function(){
			new Ajax.Request(url,{
				onComplete: function(request){
					this.update(request.responseText);
				}.bind(this)
			});
			return display_message;
		}
	});
		
	m.open();

}
var modal_replace = function(url) {
	
	new Ajax.Updater('modal_container', url, {asynchronous:true, evalScripts:true});
	
}
var modal_post = function(url, form_id) {
	new Ajax.Updater('modal_container', url, {asynchronous:true, evalScripts:true, method:'post', parameters: $(form_id).serialize() });
	return false;
}

var reposition_modal_box = function() {
	m = Control.Modal.current;
	if (m != false) {
		m.reposition();
	}
}

var close_modal = function() {
	Control.Modal.close();
}

Object.extend(Control.Modal.prototype,{
	reposition: function(html){
		this.position();
	}			  
});

function loadPhotoPosition(id) {
	modal_replace('/compose/photoposition/?data[Item][1][id]=' + id);
	//modal_ajax('Loading Next Step','/compose/photoposition/?data[Post][1][id]=' + id);
	//$('upload_frame_div').innerHTML = '';
}

function addQuestion() {
	var elementList = document.getElementsByClassName('poll_question_container');
	var thisIndex = elementList.length;
	var theNumber = thisIndex + 1;
	
	var content = '<div id="poll_question_' + thisIndex + '" class="inputContainer poll_question_container">';
	content += '<label for="poll_q_' + thisIndex + '">Poll Answer ' + theNumber + ':</label>';
	content += '<textarea class="poll_question" name="data[Poll][' + thisIndex + '][title]" id="poll_q_' + thisIndex + '" /></textarea>';
	content += '<input type="hidden" name="data[Poll][' + thisIndex + '][id]" value="" />';
	content += '</div>';
	
	new Insertion.After(elementList[elementList.length - 1], content);
	
}



