/**
 * @author stefan bukacek
 */

$(document).ready(function(){

    //redefine
    $.getaScript = function(url, callback, cache){
        $.ajax({
            type: "GET",
            url: url,
            success: callback,
            dataType: "script",
            cache: true
        });
    };

    //navi
    if ($(".navi").length > 0) {
		$.getScript("files/_js/hoverIntent.js");
        //$.getScript("files/_js/jquery.bgiframe.min.js");
        $.getScript("files/_js/superfish.js", function(){
            setTimeout(function(){
                $(".navi").superfish({
					autoArrows:  true,                           // disable generation of arrow mark-up 
		            dropShadows: true                            // disable drop shadows 
				});
            }, 200);  
        });
    };

    //fancybox
    if ($(".fancybox").length > 0) {
		$.getScript("files/_js/fancybox/jquery.fancybox-1.3.4.pack.js", function(){
            setTimeout(function(){
                $(".fancybox").fancybox({
				});
            }, 200);  
        });
    };
    
    //info
    if ($(".imgcopy").length > 0) {
                $(".slide-item").hover(
                	function() { $(".imgcopy").fadeIn(); $(".slide-controls").show(); },
                	function() { $(".imgcopy").fadeOut(); $(".slide-controls").hide(); }
				);
    };
    if ($(".maximize").length > 0) {
                $(".slide-item").hover(
                	function() { $(".maximize").fadeIn(); },
                	function() { $(".maximize").fadeOut(); }
				);
    };
    
	//ad-gallery
    if ($(".magazin-prev").length > 0) {
		$.getScript("files/_js/jquery.ad-gallery.js", function(){
            setTimeout(function(){
                $(".magazin-prev").adGallery({
					enable_keyboard_move: true
				});
            }, 400);  
        });
    };
    
	//videos
    if ($(".video-link").length > 0) {
		$.getScript("files/_js/ytChromeless/swfobject.js");
        $.getScript("files/_js/ytChromeless/jquery.ytchromeless.min.js", function(){
            setTimeout(function(){
                $("a.video-link").ytchromeless({
						videoWidth: '470'
				});
            }, 400);  
        });
    };
	//videos
    if ($(".oembed").length > 0) {
		$.getScript("files/_js/jquery.oembed.min.js", function(){
            setTimeout(function(){
                $(".oembed").oembed(null, {
                	embedMethod: "fill",
                	vimeo: { 
                		autoplay: true, 
                		maxWidth: 470
                	}
                });
            }, 400);  
        });
    };

        
    //cycle
    if ($(".slideshow").length > 0) {
		$.getScript("files/_js/jquery.cycle.lite.min.js", function(){
            setTimeout(function(){

				$('.slideshow').cycle({
				    prev: '#prev', //#id of your previous button
				    next: '#next' //#id of your next button
				});
				 
				//Handle pausing and playing
				$('#play-pause').click(function() {
				 
				  //Check to see if the slideshow is currently paused.
				  if ($(this).hasClass('paused')) {
				 
				    //Resume the slideshow, remove the class from the #play-pause button and change the text to Pause
				    $('.slideshow').cycle('resume');
				    $(this).removeClass('paused').text('Pause');
				 
				  } //if
				  else {
				 
				    //Pause the slideshow, add the paused class to the #play-pause button and change the text to Play
				    $('.slideshow').cycle('pause');
				    $(this).addClass('paused').text('Diashow');
				 
				  } //else
				 
				  //Make sure nothing else happens when you click the #play-pause button
				  return false;
				});
				
				
            }, 200);  
        });
    };
    
    
});


// add_css_class_to_selected_radio_labels
	$(document).ready(function(){
	    updateRadioLabels()
	    $('input[type=radio]').change(updateRadioLabels)
	})

	function updateRadioLabels(){
	    $('input[type=radio]').each(function(){
	        $('input[name=' + this.name +'] + label').removeClass('selected');
	        $('input[name=' + this.name +']:checked + label').addClass('selected');    
	    })
	 
	}
