/*
 * main JS Document for shortmoves.de
 * Copyright (c) 2009 Matthias Kretschmann | krema@jpberlin.de
 * http://matthiaskretschmann.com
 * http://kremalicious.com
 */
	
//On with the real fun
$(function () { //DOMdiDOM
    
    //Style outgoing links
	$('#content a').filter(function() {
		return this.hostname && this.hostname !== location.hostname;
	}).addClass('external');
	
	//Open pdf links and external links in new window
    $('a[href*=.pdf], a.external').click(function(){
		window.open(this.href);
	return false;
	});
    
    //AJAX Live Search
    $('#s').liveSearch({url: '/index.php?ajax=1&s='});
    
    //LightBox
    $('a[href*=.jpg]').lightBox({
		overlayBgColor: '#FFF',
		overlayOpacity: 0.8
   	});
   	
   	//Akkreditierungs-Formular
   	$('p.akkr').click(function(){
		$('#wpcf7-f4-p67-o1').slideToggle();
	return false;
	});
   	
   	//Ticket Price info
    $('#price').hover(function () {
    	$(this).after('<p id="priceinfo">je Besucher und Festivaltag</p>');
    	$('#priceinfo').stop().animate({ right: '-130px', opacity: '1' }, 500);  
    	}, function() { 
        $('#priceinfo').stop().animate({ opacity: '0', right: '-150px' }, 400);
    });
   	
   	//Search field fun
   	$("#sidebar #s")
    .val("Suche...")
    .css("color", "#ccc")
    .focus(function(){
        $(this).css("color", "black");
        if ($(this).val() == "Suche...") {
            $(this).val("");
        }
    })
    .blur(function(){
        $(this).css("color", "#ccc");
        if ($(this).val() == "") {
            $(this).val("Suche...");
        }
    });
    
    //program mosaic switch
    $('h3.programdate').after('<ul class="view-switch"><li class="normal">Normal</li><li class="mosaic">Mosaik</li></ul>');
	var $filmbox = $('.film')
	$('li.normal').click(function(){
		$filmbox.hide().removeClass('mosaic').fadeIn();
	return false;
	});
	$('li.mosaic').click(function(){
		$filmbox.hide().addClass('mosaic').fadeIn();
	return false;
	});
	
	//Google Map
	if ( $("#googlemap").length > 0 ) {
	
		  if (GBrowserIsCompatible()) {
			  function createMarker(point,html) {
				var marker = new GMarker(point);
				GEvent.addListener(marker, "click", function() {
				  marker.openInfoWindowHtml(html);
				});
				return marker;
			  }
			  
			  function createMarker(point,html) {
				var marker = new GMarker(point);
				GEvent.addListener(marker, "click", function() {
				  marker.openInfoWindowHtml(html);
				});
				return marker;
			  }
		
			  var map = new GMap2(document.getElementById('googlemap'));
			  var luxzoo = new GLatLng(51.504956,11.959429);
			  map.addControl(new GSmallMapControl());
			  map.setCenter(luxzoo, 13);
			  
			  var point = luxzoo;
			  var marker = createMarker(point,'<div style="width:250px"><img align="left" class="alignleft" src="http://mw2.google.com/mw-panoramio/photos/iw-small/10220452.jpg" /><p>LUX.KINO AM ZOO</p><p>Seebener Straße 172/Hintereingang Zoo</p><p>06114 Halle/Saale</p><p><a href="http://www.luxkino.de/">LUX.KINO Web Site</a></p></div>');
			  map.addOverlay(marker);
			  GEvent.addListener(marker, "click", function(){
        		map.panTo(point);
    			});

			}
			else {
			  alert("Sorry, the Google Maps API is not compatible with this browser");
			}
    }
    
    //the warning toggle for IE 7 and below users	
    $('#warning-toggle').click(function() {
    	$('#iewarning').slideUp(500);
    	$('#warning-toggle').fadeOut('normal')
    	$.cookie('panelState', 'collapsed');
    	return false;
    });
    var panelCookie = $.cookie('panelState');
    if (panelCookie == 'collapsed') {
 		$('#iewarning,#warning-toggle').hide();
 	}

});//don't delete me or the DOM will collaps

//Finally load all this after the content has loaded
$(window).load(function() {
	
	//AddThis widget
    $.getScript('http://s7.addthis.com/js/250/addthis_widget.js', function(){
  	var $trigger = $('#share a');
    $trigger.hover(function () {
    	$(this).stop().animate({ top: '0' }, 300);
    	return addthis_open(this, '', '[URL]', '[TITLE]');
    	}, function() { 
        $(this).stop().animate({ top: '-20px' }, 300);
        addthis_close()
        $trigger.click(function(){addthis_open(this, '', '[URL]', '[TITLE]');
		return false;
		});
    });
	});
	
	//Grab the latest tweet...
    if ( $("#tweet").length > 0 ) {
	    $("#tweet").tweet({
          join_text: "",
          username: "shortmoves",
          avatar_size: 36,
          count: 6,
          loading_text: "loading tweets...",
          query: "shortmoves"
        });
    }
	
});