var cookieCities = '';

function save_cities(pipe) {
    cookieCities = pipe;
  
    if (ajaxRequest != undefined) {
        ajaxRequest.abort();
    }
    ajaxRequest = $.get(absolute_path + 'ajax.php?cmd=updateCities',
        { 
            pipe: pipe
        },
        function(data)
        {
            $("div#cities_list").html(data);
            var date = new Date();
            date.setTime(date.getTime() + (365 * 24 * 60 * 60 * 1000));
            $.cookie('cities_cinema', pipe, { expires: date, path: '/' });
        }
     );
    
}

function addJqueryMemberspaltenFunctionality() {
	
	// Sparten auf/zuklappen
    $("img.memberspalte_plusminus").click(function () {
        var id = $(this).parent().parent().attr('id');
        var content = id + '_content';
        var spalten_index = $("img.memberspalte_plusminus").index(this);
        if ($('div#' + content).is(':hidden')) {
            this.src = '/img/global/icons/minus_12px.gif';
            $("div#" + content).slideDown("fast", function () {
                set_memberspalte_cookie();
            });
        }else {
            this.src = '/img/global/icons/plus_12px.gif';
            $("div#" + content).slideUp("fast", function () {
                set_memberspalte_cookie();
            });
        }
        return false;
    });
    
    // Reiter switchen
    $("li.left_tab").click(function () {
        var id = $(this).parent().parent().parent().attr('id');
        $("div#" + id + "> div.tab_1").show();
        $("div#" + id + "> div.tab_2").hide();
        set_memberspalte_cookie();
        return false;
    });
    $("li.right_tab").click(function () {
        var id = $(this).parent().parent().parent().attr('id');
        $("div#" + id + "> div.tab_1").hide();
        $("div#" + id + "> div.tab_2").show();
        set_memberspalte_cookie();
        return false;
    });
    
    // Memberspalten-Cookie setzen
    function set_memberspalte_cookie() {
        var pipe = '';  
        $('div.membercontent').each(function(idx, item) {
            if (item.style.display == 'block') {
                pipe+= '1';
            }else {
                pipe+= '0';
            }
            var tab_1 = $(this).find("div.tab_1");
            if (tab_1.length) {
                if (tab_1.css("display") == 'block') { 
                    pipe+= '-1';
                }else{
                    pipe+= '-2';
                }
            }
            pipe+= '|';
        });
        $.cookie('status_memberspalte', pipe, { expires: 365, path: '/', domain: 'cineman.ch', secure: false });
        return false;
    }
    
    $("p#show_login").click(function () {
        $("div#login_part").slideDown("fast", function () { $("p#show_login").hide(); })
        return false;
    });
}

// Macht ganze Teaser klickbar und hovert sie. global_styles.css wird dazu benötigt, ist aber eh überall vorhanden.
function addHoverTeaser(css_class) {
	$('div.'+css_class).mouseover( function () { $(this).addClass('teaser_hover'); } );
	$('div.'+css_class).mouseout( function () { $(this).removeClass('teaser_hover'); } );
	$('div.'+css_class).click( function () { location.href = $(this).children("div.teaserContent").children("p.title").children("a").attr('href'); } );
}


	// Hinzufügen einer Default-Action zu einer Auflistungs-Tabelle:
	$(document).ready( function() {
	// Hand Cursor für Tabellen mit defaultAction-Klasse
	$('table.listing tr td.defaultAction').closest('tr').attr('style', 'cursor: pointer');
	$('table.listing tr').click( function(e) {
		// Greift nicht bei Links:
		if ($(e.target).is('a') || $(e.target).parents().is('a')) {
			return;
		}

		var hasAction = ($(e.target).siblings('.defaultAction'));
		// Leite zur Default-Action weiter:
		if (hasAction.length) {
		    e.preventDefault();
		    var actionUrl = hasAction.children('a').attr('href');
		    if (actionUrl) {
		    	window.location.href = actionUrl;
			}
		}
	});
});

