if (debug == undefined) var debug = false;

$(document).ready(function() {
	// activate the example plugin for the search input field
	$('.has-example').example(function() {
		return $(this).attr('title');
	});
	
	// alternate rows for the tea-list
	$(".tea-list .tea:even").addClass('tea-even');
	
	initImageboxes();
	
	// breadcrumb: the first element get the class "first"
	$('.breadcrumbs ul li:first').addClass('first');
	
	// Quicklinks aktivieren
	$('.quicklinks').change(function() {
		if (this.selectedIndex > 0) {
			window.location.href = '/' + this.options[this.selectedIndex].value;
		}
	});
	
	// Modify the contact list teaser
	$('.rc-tea-contacts-list .contact:last').addClass('contact-last');
	
	// Modify the job list teaser
	$('.rc-tea-jobs .jobs:last').find('li:last').addClass('last');

	// open pdf files in new windows
	$("a[href*=.pdf]").click(function(){
		window.open(this.href);
		return false;
	});

	/* open class="external" in new window
	$('a[class="external"]').click( function() {
		window.open( $(this).attr('href') );
		return false;
	});
  */
  $("a[href*='http://']:not([href*='"+location.hostname+"'])").attr("target","_blank").click(function(){
		window.open(this.href);
		return false;
	});
  
	if ($('#mycarousel').length > 0) {
    		init_imageslides();
  	}
  	
  $("#tipaFriendForm").validate({ 
      rules: {
    		"TIPFORM[name]": "required", 
    		"TIPFORM[email]": {
				  required: true,
				  email: true
			   },
  			"TIPFORM[recipient]": {
	   			required: true,
				  email: true
		  	}
    	}, 
    	messages: {
    		 "TIPFORM[name]": 'Bitte geben Sie Ihren Benutzernamen ein.', 
			   "TIPFORM[email]": 'Bitte geben Sie Ihre g&uuml;ltige E-Mail-Adresse an.',
			   "TIPFORM[recipient]": 'Bitte geben Sie eine g&uuml;ltige E-Mail-Adresse für die Empfänger.'}
	      }); 
 
      if($("h1.csc-firstHeader").text() == "Seite weiterempfehlen" || $("h1.csc-firstHeader").text() == "Seite nicht gefunden"){
        $(".options-bar").attr("style","display:none");
      }
	
  initFlashVideoPlayer();
	customStyles();
})


/**
 *	Set the absolute width to all imageboxes according to the placed image.
 *	Need to avoid the line braking of the image description text
 *	@author Gleb Kotov
 */
function initImageboxes() { 
	$('.imagebox').each(function() {
		var width = $(this).find('img').width();
		if (width) {
			$(this).width(width + 5);
		}
	})
}

function initCycle(id) {
	var obj = $('#' + id);
	if (obj) {
		if (obj.find('.image-slides').eq(0).find('.image-slide').length > 1) {
			$('#' + id + ' .image-slides').cycle({ 
			    fx:     'scrollHorz',
				speed:  'fast',
			    timeout: 0,
				next:   '#' + id + ' .next',
				prev:   '#' + id + ' .prev'
			});
		} else {
			// there is only one slide
			obj.find('.prev-box').css('visibility', 'hidden');
			obj.find('.next-box').css('visibility', 'hidden');
		}
		
	}
}

/**
 * carousel init callback
 * 
 * @param {Object} carousel
 */
var mycarousel_itemList = new Array();

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_itemList[idx - 1]);
};

function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};

function init_imageslides() {
  $('li[class="mycarouselList"]').each(function() {mycarousel_itemList.push(this.innerHTML);})
  $('#mycarousel').show();
  $('#mycarousel').jcarousel({
	    scroll: 1,
    	wrap: 'circular',
    	itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
      itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
} 

 /**
 *  flash-video player
 *  obtains the required Data(File,image) for the predefined Videoplayer
 */

	function initFlashVideoPlayer() {
		$('.flash-player').each(function(counter) {
			var playerWidth, playerHeight;
			var genId = "flashPlayer" + counter;
			$(this).find(".flash-con").attr('id', genId);
			if ($(this).find(".flash-con").hasClass("vpl1c")) {
				playerWidth = 400;
				playerHeight = 266;
			}
			if ($(this).find(".flash-con").hasClass("vpc")) {
				playerWidth = 669;
				playerHeight = 376;
			}
			var playerFile = '../flash/player.swf';
			var videoFile = $(this).find('.inputFile').attr('value');			
			if	(!debug) {
				playerFile = 'fileadmin/BDS/images/' + playerFile;
				videoFile = '../../../' + videoFile; // information is stored in the input field, filled through the editors at the corresponding templaVoila Module
			}
			var s1 = new SWFObject(playerFile, 'player', playerWidth, playerHeight, '9'); // for local environment
			var image = $(this).find('.inputPreviewImage').attr("value"); // information is stored in the input field, filled through the editors at the corresponding templaVoila Module
			s1.addParam('allowfullscreen','true');
			s1.addParam('allowscriptaccess','always');
			s1.addParam('flashvars', 'file=' + videoFile + '&image=' + image + '&controlbar=over');
			s1.write(genId);
		});
	}

 /**
 * End flash-video player
 */
 
 /**
 *  customStyles
 * customize different styles
 */
	function customStyles() {
	
		// remove inline style from the map resize Link at googleMaps
		$(".gs-box").find("small > a").removeAttr("style");
	}

 /**
 * End  customStyles
 */

// Die Seite wird gedruckt
function printPage() {
	window.print();
}

