var amp = '&';

//fix footer in ie6
$('#footer').css('display', 'none');
$('#footer').css('display', 'inline');

$(function () {
	$(window).load(function () {
		$(':input:visible:enabled:first').focus();
	});
})


// right widget
$(document).ready(function(){
/* for($i=1;$i<=3;$i++){
 	$('#answer'+$i).hide();
 }*/

	$('#content a.lightBox').lightBox(); // Select all links in object with gallery ID

	if(document.getElementById("datepik")){
		date_obj = new Date();
		date_obj_hours = date_obj.getHours();
		date_obj_mins = date_obj.getMinutes();
		if (date_obj_mins < 10) {
			date_obj_mins = "0" + date_obj_mins;
		}

		date_obj_time = "'"+date_obj_hours+":"+date_obj_mins+"'";

		// Datepicker
		$('#datepik').datepicker({
			dateFormat: 'MM dth, yy,' + date_obj_time
		});
	}
});

/*
function question($id){
	$('#answer'+$id).slideToggle("slow",function () {
			$('#footer').css('display', 'none');
			$('#footer').css('display', 'inline')
		}
	);
}
*/
function sendAjax(toFile,sendData,useReturned) {
	$.ajax({
	type: "POST",
	url: toFile,
	data: sendData,
	dataType: 'json',
	success: useReturned
	});
}

// show content
function setNewsValues(cont){
	$("#date").attr("value",cont.date);
	$("#title").attr("value",cont.title);
	tinyMCE.get('text').setContent(cont.text);
}

function save() {
	tinyMCE.triggerSave();
	$("#date").attr('value',$("#datepik").attr('value'));
	if(($("#date").attr("value") != '') && ($("#title").attr("value") != '') && ($("#text").attr("value") != '')) {
		var str = $("#newsEditorForm").serialize();
		sendAjax("/ajax/savenews","submit=submit" + amp + str, pageUpdate);
	}
};

function deletenews() {
	var str = $("#newsEditorForm").serialize();
	sendAjax("/ajax/deletenews","submit=submit" + amp + str, pageUpdate);
};

function pageUpdate(bool) {
	if(bool == true) {		window.location.href="/admin/newseditor"
	}
}

function loadNewsData() {
	var str = $("#newsEditorForm").serialize();
	sendAjax("/ajax/loadnews",str, setNewsValues);
}

function selectSubTab(id){
	$('.divSubTabs').hide();
	$('#' + id).show();
	$('.tab').removeClass('horizontalTabSelect').addClass('horizontalTab');
	$('#tab-' + id).removeClass('horizontalTab').addClass('horizontalTabSelect');
}
