// definitions
jQuery.noConflict();

// startup jobs
jQuery(document).ready(function() {
    
    
		
		// initiate jplayer   
		if(jQuery('.jplayer').length > 0){
	    jQuery('.jplayer').each(function(key,value){
				
	    	//console.log(key+' : '+jQuery(this).attr('href'));

	    	var path = jQuery(this).attr('href');

	    	jQuery(this).after(printJplayer(key));
	    	//console.log(jQuery('#jquery_jplayer_'+key).attr('id'));


				jQuery('#jquery_jplayer_'+key).jPlayer({
					ready: function () {
						jQuery('#jquery_jplayer_'+key).jPlayer("setMedia", {
							mp3:path
						});
					},
					play: function() { // To avoid both jPlayers playing together.
						jQuery('#jquery_jplayer_'+key).jPlayer("pauseOthers");
					},
					swfPath: "fileadmin/templates/ai2011/main/js/lib/jplayer",
					supplied: "mp3",
					cssSelectorAncestor: "#jp_container_"+key,
					wmode: "window"
				});				
	    }); //end each
		}
		
		//fancybox for rgnewsimages
		if(jQuery('.news-single-img a').length > 0){
        //JQuery workaround writes imagecaption in title tag for fancybox
        jQuery('.news-single-img a').each(function () {
        var caption = jQuery(this).next('.news-single-imgcaption').text();
        jQuery(this).attr('title',caption);
        jQuery(this).find('img').attr('title',caption);
        jQuery(this).find('img').attr('alt',caption);
      });
      
			//initialize fancybox for all rg news images
      jQuery('.news-single-img a').fancybox({
      	overlayShow: true,
      	speedIn : 300,
      	speedOut : 300,
      	'transitionIn'  :  'elastic',
      	'transitionOut'  :  'elastic',          
      	overlayOpacity: 0.75,
      	overlayColor: '#000000',
      	centerOnScroll:  true
      });      	
		}
		
		// equalize columns
    equalHeight(jQuery(".column"));		
		    
});






// functions
function equalHeight(group) {
    var tallest = 0;
    group.each(function() {
        var thisHeight = jQuery(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    tallest < jQuery(window).height() ? tallest = jQuery(window).height() * 1.01 : tallest;
    group.height(tallest);
}



function printJplayer(key){
	return '<div id="jquery_jplayer_'+key+'" class="jp-jplayer"></div><div id="jp_container_'+key+'" class="jp-audio"><div class="jp-type-single"><div class="jp-gui jp-interface"><ul class="jp-controls"><li><a href="javascript:;" class="jp-play" tabindex="1">play</a></li><li><a href="javascript:;" class="jp-pause" tabindex="1">pause</a></li><li><a href="javascript:;" class="jp-stop" tabindex="1">stop</a></li><li><a href="javascript:;" class="jp-mute" tabindex="1" title="mute">mute</a></li><li><a href="javascript:;" class="jp-unmute" tabindex="1" title="unmute">unmute</a></li><li><a href="javascript:;" class="jp-volume-max" tabindex="1" title="max volume">max volume</a></li></ul><div class="jp-progress"><div class="jp-seek-bar"><div class="jp-play-bar"></div></div></div><div class="jp-volume-bar"><div class="jp-volume-bar-value"></div></div><div class="jp-time-holder"><div class="jp-current-time"></div><div class="jp-duration"></div><ul class="jp-toggles"><li><a href="javascript:;" class="jp-repeat" tabindex="1" title="repeat">repeat</a></li><li><a href="javascript:;" class="jp-repeat-off" tabindex="1" title="repeat off">repeat off</a></li></ul></div></div><div class="jp-title"><ul><li>Cro Magnon Man</li></ul></div><div class="jp-no-solution"><span>Update Required</span>To play the media you will need to either update your browser to a recent version or update your <a href="http://get.adobe.com/flashplayer/" target="_blank">Flash plugin</a>.</div></div></div>';
}
