var ie_version;

$(document).ready(function() {

	if (!ie_version || ie_version > 6){
		$("body").addClass("dynamic");
	}
	
	if (ie_version <= 7){
		$(".column").removeClass("dynamic");
	}
	
// Myzone sortieren
	
	$(".column.dynamic").sortable({
		connectWith: '.column.dynamic',
		handle: 'caption',
		update: function(event, ui) {
			var col_id = $(this).attr("id");
			var col_arr = $(this).sortable('toArray');
			$.ajax({
		            type: "POST",
		            url: "ajax.php",
		            dataType: 'json',
		            data: "mode=movelist&col_id=" + col_id + "&col_arr=" + col_arr,
		            cache: false,
		            beforeSend: function(data) {
		            },
		            success: function(data) {
		               	if(data.status){
		               	}else{
		               		alert("Es ist ein Fehler aufgetreten");
		               	}
		            }, error: function(data) {
		                alert("Es ist ein Fehler aufgetreten");
		            }
			});
		}
	});
	
	$(".column").disableSelection();
	
	
// Thema abonnieren

    $(".checked").live('click', function() {
		if($(this).attr("id")){
	    	set_subscription(this, "unchecked");
	    	return false;
		}
    });
    
	$(".unchecked").live('click', function() {
		if($(this).attr("id")){
			set_subscription(this, "checked");
			return false;
		}
    });
	
// Tabellen in MyZone ein- und ausblenden	
	
    $(".closelist").live('click', function() {
    	toggle_list($(this), 0, "Liste ausklappen");
    });
	
    $("#publishing_info_toggle").live('click', function() {
    	$("#publishing_info").toggle();
		return false;
    });	
    
    $(".openlist").live('click', function() {
    	toggle_list($(this), 1, "Liste einklappen");
    }); 
    
    function toggle_list(elem, status, linktitle){
    	var fid = $(elem).parents(".tablewrapper").attr("id");   	
    	
    	$.ajax({
            type: "POST",
            url: "ajax.php",
            dataType: 'json',
            data: "mode=togglelist&status=" + status + "&fid=" + fid,
            cache: false,
            beforeSend: function(data) {
            },
            success: function(data) {
               	if(data.status){
            		$(elem).parents(".tablewrapper").children("table").children("thead").toggle();
            		$(elem).parents(".tablewrapper").children("table").children("tbody").toggle();
            		$(elem).parents(".tablebottom").children(".bottom_left").toggle();
        			$(elem).toggleClass("closelist").toggleClass("openlist").html(linktitle);
               	}else{
               		alert("Es ist ein Fehler aufgetreten");
               	}
            }, error: function(data) {
                alert("Es ist ein Fehler aufgetreten");
            }
        });
    } 
});

function set_subscription(obj, stype){
	
	$.ajax({
        type: "POST",
        url: "ajax.php",
        dataType: 'json',
        data: "mode=subscription&stype=" + stype + "&tid=" + $(obj).attr("id"),
        cache: false,
        beforeSend: function(data) {
        },
        success: function(data) {
           	if(data.status == "success"){
           		$(obj).removeClass().addClass(stype);
           		$(obj).attr("title", data.title);
           		$(obj).html(data.text);
           	}
        }, error: function(data) {
            alert("Es ist ein Fehler aufgetreten");
        }
    });
}

/*function blub(elem){
	var tag = $(elem).attr("id");
	var option = $('#'+tag +' option:selected').val();
	$('#tag2_' + option).hide();
	$('select option').show();
}*/
