/**
 * Javascript-Functions - PROJECT
 * (c) CLICKSPORTS DIGITAL SOLUTIONS
 * http://www.clicksports.de
 * 
 * $Rev: 2184 $
 * $Author: mw $
 * $Date: 2010-07-19 15:07:42 +0200 (Mo, 19 Jul 2010) $
 */


Cufon.replace('h1');
Cufon.replace('h2');
Cufon.replace('ul#navigation > li > a');

$(document).ready(function() {

  getBlitzer();

  // Only run automatically when we have the first run
  if(CS.mp3autoplay) {

    $("#music").jPlayer({
      ready: function () {
        $(this).jPlayer("setMedia", {
          mp3: CS.mp3file
        }).jPlayer("play");
      },
      ended: function (event) {},
      swfPath: "js",
      supplied: "mp3"
    });
  } else {
    $("#music").jPlayer({
      ready: function () {
        $(this).jPlayer("setMedia", {
          mp3: CS.mp3file
        });
      },
      ended: function (event) {},
      swfPath: "js",
      supplied: "mp3"
    });
  }

	/* Adding a colortip to any tag with a title attribute: */
	$('.contents [title]').colorTip({color:'blue'});

	$("#navigation").accordion({
		navigation: true,
		header: '.head',
		autoheight: false,
		navigationFilter: function() {
			
			var is_active = false;
			if(this.href.toLowerCase() == location.href.toLowerCase() || $(this).hasClass('active')) is_active = true;
			return is_active;
		}
	});
	
	var allowedExtensions = ['jpg', 'jpeg', 'png', 'gif'];
	$.each($('.contents a'), function() {
		
		var myext_arr = $(this).attr('href').split('.');
		if($.inArray(myext_arr[myext_arr.length-1], allowedExtensions) !== -1) {
			
			$(this).fancybox();
			$(this).addClass('no_bg');
		}
	});

	$('.images a').fancybox();
});

$(document).ready(function() {
    $('#teaser').nivoSlider({
        effect:'fade', //Options: sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade, random / Specify sets like: 'fold,fade,sliceDown'
        slices:1,
        animSpeed:1000, //Slide transition speed
        pauseTime:5000,
        startSlide:0, //Set starting Slide (0 index)
        directionNav:false, //Next & Prev
        directionNavHide:true, //Only show on hover
        controlNav:false, //1,2,3...
        controlNavThumbs:false, //Use thumbnails for Control Nav
        controlNavThumbsFromRel:false, //Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', //Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
        keyboardNav:false, //Use left & right arrows
        pauseOnHover:false, //Stop animation while hovering
        manualAdvance:false, //Force manual transitions
        captionOpacity:0.8, //Universal caption opacity
        beforeChange: function(){},
        afterChange: function(){},
        slideshowEnd: function(){}, //Triggers after all slides have been shown
        lastSlide: function(){}, //Triggers when last slide is shown
        afterLoad: function(){} //Triggers when slider has loaded
    });
});

/**
 * Get blitzers from radioeins
 */
function getBlitzer() {
       
        var elm = jQuery('#speed_camera_content');
       
        jQuery.getJSON("http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22http%3A%2F%2Fradioeins.com%2Fdefault.aspx%3FID%3D4729%22%20and%0A%20%20%20%20%20%20xpath%3D'%2F%2Fdiv%5B%40class%3D%22radioblitzercontent%22%5D'&diagnostics=true&callback=?", function(data) {
           
            if(data.query.count > 0) {
                   
                    var content = '';
                    var nocontent = '<div class="noblitzer">Es wurden keine Blitzer gefunden</div>';
                    jQuery.each(data.results, function() {
                           
                                // If we have no output, dont show the block
                                if(this.indexOf('Momentan keine') === -1) {
                                       
                                        content += this;
                                }
                    });
                   
                    if(content.length === 0) content = nocontent;
                    else content = '<div class="blitzerfound">' + content + '</div>';
                    elm.html(content);
            } else {
              
              var content = '<p>Aktuell keine Blitzer vorhanden.</p>';
              elm.html(content);
            }
       
        });

}

