var gui = {
	photoArray: {},
	getPlayers: function (selector) {
		$.getJSON("https://picasaweb.google.com/data/feed/base/user/viphotos2011/albumid/5620628453270828929?alt=json&kind=photo&hl=en_GB&callback=?", function (data) {
			$.each(data.feed.entry, function (i, item) {
				gui.photoArray[item.title.$t] = item.media$group.media$thumbnail[1].url;
			});
			gui.updatePictures(selector);
			$(selector + ' tr').find('td:eq(6)').readmore({
				"substr_len": 80
			});
		});
	},
    fancyConfirm: function(msg,callback) {
        var ret;
        $.fancybox({
            modal : true,
            content : "<div style=\"margin:1px;width:240px;\">"+msg+"<div style=\"text-align:right;margin-top:10px;\"><input id=\"fancyConfirm_cancel\" type=\"button\" class=\"btn red\" value=\"Cancel\"><input id=\"fancyConfirm_ok\" class=\"btn red\" type=\"button\" value=\"Ok\"></div></div>",
            onComplete : function() {
                $("#fancyConfirm_cancel").click(function() {
                    ret = false; 
                    $.fancybox.close();
                })
                $("#fancyConfirm_ok").click(function() {
                    ret = true; 
                    $.fancybox.close();
                })
            },
            onClosed : function() {
            if(ret){
                callback.call(this,ret);
                }
            }
        });
    },
	updatePictures: function (selector) {
		$(selector).dataTable({
			"iDisplayLength": 25,
			"aaSorting": [
				[0, 'desc']
			],
			"aLengthMenu": [
				[25, 50, 100, -1],
				[25, 50, 100, "All"]
			],
			"fnDrawCallback": function () {
				$(selector + " tbody tr").find("td:eq(1)").each(function () {
					var name = $(this).text();
					if (name in gui.photoArray) {
						$(this).prev().find("img").attr("src", gui.photoArray[name]);
					}
				});
			}
		});
	},
	editNews: function () {
		var oTable = $('table.editNews').dataTable();
		$('td', oTable.fnGetNodes()).editable('/admin/editable_ajax.php', {
			"type": 'textarea',
			"tooltip": 'Click to edit...',
			"cancel": 'Cancel',
			"submit": 'OK',
			"cssclass": 'editTableText',

			"callback": function (sValue, y) {
				var aPos = oTable.fnGetPosition(this);
				oTable.fnUpdate(sValue, aPos[0], aPos[1]);
			},
			"submitdata": function (value, settings) {
				return {
					"row_id": this.parentNode.getAttribute('id'),
					"column": oTable.fnGetPosition(this)[2]
				};
			}
		});
	}
};

$(document).ready(function () {
	$("div.newsbox").find("img").remove();
	$('#nav').underNav({
		speed: 1000,
		easing: 'easeOutExpo'
	});
	$("li", $('#topnav')[0]).hover(

	function () {
		$(this).addClass("subhover");
		$(this).find("ul.subnav").stop(true, true).slideDown('fast').show();
	}, function () {
		$(this).removeClass("subhover");
		$(this).find("ul.subnav").delay(100).slideUp('fast');
	});
	$('a', $('#topnav')[0]).mouseenter(function () {
		if (!$(this).parent().parent().hasClass("topnav")) {
			$(this).animate({
				'opacity': "0.40"
			}, 300).animate({
				'opacity': "1"
			}, 300);
		}
	});
	$("#open").click(function () {
		$("div#panel").slideDown("slow");
		//$("#container").animate({"margin-top":"250px"},1000);
	});

	// Collapse Panel
	$("#close").click(function () {
		$("div#panel").slideUp("slow");
		//$("#container").animate({"margin-top":"10px"},1000);
	});

	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});
	$('#removeLogin').live("click", function () {
		$('#toppanel').remove();
	});
	$('table.display').dataTable({
		"iDisplayLength": 25,
		"aaSorting": [
			[0, 'desc']
		],
		"aLengthMenu": [
			[25, 50, 100, -1],
			[25, 50, 100, "All"]
		]
	});
	$(".bt_register").live("click", function(){
	$.fancybox(
		'<h2>Hi! We sorry!</h2><p>Unfortunately registration is working at the moment, please check back soon</p>',
		{
        	'autoDimensions'	: true,
        	'scrolling'	: "no"
		}
	);
	return false;
	});
});


