 function colored () {

	$('.colored_table tr').filter(':even').addClass('even');
	
	
	$('ul.colored').each(function(){
		$(this).children('li').filter(':odd').addClass('even');
								})
					} 
					
   function fancybox_init() {
      $('a.fancybox').fancybox({
		 hideOnContentClick: true,
		 titlePosition : 'over',
		 autoScale  :  false
	   });
	   
	    $('a.fancybox_noresize').fancybox({
		autoScale  :  false,
		autoDimensions	: false,
		width       	: 600,
		height     		: 'auto',
		transitionIn	:	'elastic',
		transitionOut	:	'elastic',
		speedIn			:	600, 
		speedOut		:	200
	   });
	   
	   
	   $('a.fancybox_video').fancybox({
			autoScale		: false,
			transitionIn	: 'none',
			transitionOut	: 'none',
			title			: this.title,
			width		: 640,
			height		: 480,
			type 			: 'swf'
	   });
	   
   

   }
   
   
   function accordion () {
	$("#accordion").tabs("#accordion div.pane", {tabs: 'b', effect: 'slide', initialIndex: null});   
   }
   
   
   
function openhide_blocks () {
	$(".positions .item .btn").click(function() {
		if ($(this).parent().hasClass("current")) {
			$(this).parent().removeClass("current");
			$(this).parent().addClass("closed");
		 	//$("ol", $(this).parent()).fadeOut("normal");
			//$(".content", $(this).parent()).slideUp("slow");
			$(".content", $(this).parent()).fadeOut("slow");
		 	
		} else {
			$(this).parent().hasClass("closed");
			$(this).parent().removeClass("closed");
			$(this).parent().addClass("current");
		 	//$("ol", $(this).parent()).fadeIn("normal");
			$(".content", $(this).parent()).slideDown("slow");
		}
	 	
		return false;
	});
	
	$(".cp .items .unit").hover(function() {
	/*$(".logo", this).addClass("over");*/
	$(this).addClass("over");
 	$(".letters", this).show();
	
		}, function() {
		 $(".letters", this).hide();
		 /*$(".logo", this).removeClass("over");*/
		 	 $(this).removeClass("over");
		});
}

function modal () {
		//$(".modal_open[rel]").overlay({mask: '#000', effect: 'apple'});
}



function inputStyling() {
	$('input[type=file]').each(function(){
 
  var uploadbuttonlabeltext = $(this).attr('title'); //get title attribut for languagesettings
  if(uploadbuttonlabeltext == ''){
    var uploadbuttonlabeltext = 'Browse';
  }
 
  var uploadbutton = '<input type="button" class="button_button" value="'+uploadbuttonlabeltext+'" />';
   $(this).wrap('<div class="fileinputs"></div>');
    $(this).addClass('file').css('opacity', 0); //set to invisible
    $(this).parent().append($('<div class="fakefile" />').append($('<input type="text" class="string" />').attr('id',$(this).attr('id')+'__fake')).append(uploadbutton));
 
    $(this).bind('change', function() {
      $('#'+$(this).attr('id')+'__fake').val($(this).val());;
    });
    $(this).bind('mouseout', function() {
      $('#'+$(this).attr('id')+'__fake').val($(this).val());;
    });
  });
 
}

function ajax_calendar() {
   $('a.ajax').live('click', function(){
      var url = $(this).attr('href');
      var context = $('div#'+$(this).attr('rel'));
      
      var loading_wrapper = document.createElement('div');
      $(loading_wrapper).addClass('date_field_calendar_loading_wrapper');
      
      var loading = document.createElement('div');
      $(loading).addClass('date_field_calendar_loading');
      
      loading.style.width = $(context).width() + 'px';
      loading.style.height = $(context).height() + 'px';
      loading.style.top = '-' + $(context).height() + 'px';
      
      loading_wrapper.appendChild(loading);
      
      $(context).append(loading_wrapper);
      
      $.ajax({
         context : context,
         url : url,
         type : 'POST',
         success : function(data, textStatus, XMLHttpRequest) {
            $(this).html(data);
         }
      });
      
      return false;
   });   
}

function news_titles_resize() {
	var ipl = 3;
	var titles = $(".news_list .col .news_title");
	$(titles).height("auto");
	var maxTH = [];
	
	for (x = 0; x < titles.length; x += 1) {
		var row = Math.floor(x / ipl);
		
		if (!maxTH[row]) {
			maxTH[row] = 0;
		}
		
		var th = $(titles[x]).height();
		
		if (th > maxTH[row]) {
			maxTH[row] = th;
		}
	}
	
	for (x = 0; x < titles.length; x += 1) {
		var row = Math.floor(x / ipl);
		$(titles[x]).height(maxTH[row]);
	}
}


function selectStyling () {
		$('.auto_select').styledSelect();
}

function tabs_init() {
   $("#puzzleoffMap").tabs("div.panes > div");
}


$(document).ready(function(){
	colored ();
	fancybox_init();
	accordion ();
	openhide_blocks ();
	modal ();
	inputStyling();
	selectStyling ();
	ajax_calendar();
	news_titles_resize();
	tabs_init();
});

$(window).load(function() {
	if ($("#puzzleoffMap").length) {
		var puzzle = {
			img : $("#puzzleon")[0],
			coords : {
				1 : "M0,0v213h634V0H0z M253.5,48.5c0,3-4,8-4,11c0,2,1,8,5,8h62v58c-1,3-4,6-6,6c-3,0-8-3-11-3c-9,0-10,4-10,10c0,9,4,11,10,11c3,0,8-3,11-3c2,0,6,2,6,5v59h-60c-2-1-6-5-6-7c0-3,4-8,4-11c0-7-5-9-10-9c-7,0-9,4-9,9c0,3,4,8,4,11c0,2-4,7-7,7h-59v-63c-2-4-6-4-8-4c-3,0-8,4-11,4c-6,0-8-8-8-9c0-6,7-8,8-8c3,0,8,4,11,4c2,0,6-1,8-5v-62h61c5-1,6-6,6-8c0-3-4-8-4-11s5-8,8-8C250.5,40.5,253.5,47.5,253.5,48.5z M374.5,67.5c4-1,9,4,9,7c0,2-4,8-4,10c0,7,4,10,9,10c7,0,10-5,10-10c0-2-4-8-4-10c0-3,3-7,6-7h59v58c-1,3-4,6-6,6c-3,0-8-3-11-3c-9,0-10,4-10,10c0,9,4,11,10,11c3,0,8-3,11-3c2,0,6,2,6,5v59h-141v-63c-2-4-6-4-8-4c-3,0-8,4-11,4c-6,0-8-8-8-9c0-6,7-8,8-8c3,0,8,4,11,4c2,0,6-1,8-5v-62H374.5z	 M604.5,67.5v61c1,5,5,6,8,6c2,0,8-4,10-4c6,0,9,7,9,8c0,6-8,9-9,9c-2,0-8-4-10-4c-3,0-8,1-8,5v62h-60c-2-1-6-5-6-7c0-3,4-8,4-11c0-7-5-9-10-9c-7,0-9,4-9,9c0,3,4,8,4,11c0,2-4,7-7,7h-59v-63c-2-4-6-4-8-4c-3,0-8,4-11,4c-6,0-8-8-8-9c0-6,7-8,8-8c3,0,8,4,11,4c2,0,6-1,8-5v-62H604.5z",
				2 : "M0,0v213h634V0H0z M86.5,67.5c4-1,9,4,9,7c0,2-4,8-4,10	c0,7,5,10,9,10c7,0,10-5,10-10c0-2-4-8-4-10c0-3,3-7,6-7h59v58c-1,3-4,6-6,6c-3,0-8-3-11-3c-9,0-10,4-10,10c0,9,4,11,10,11	c3,0,8-3,11-3c2,0,6,2,6,5v59h-141v-63c-1-4-6-4-8-4c-3,0-8,4-11,4c-6,0-8-8-8-9c0-6,7-8,8-8c3,0,8,4,11,4c2,0,7-1,8-5v-62H86.5z	 M374.5,67.5c4-1,9,4,9,7c0,2-4,8-4,10c0,7,4,10,9,10c7,0,10-5,10-10c0-2-4-8-4-10c0-3,3-7,6-7h59v58c-1,3-4,6-6,6c-3,0-8-3-11-3	c-9,0-10,4-10,10c0,9,4,11,10,11c3,0,8-3,11-3c2,0,6,2,6,5v59h-141v-63c-2-4-6-4-8-4c-3,0-8,4-11,4c-6,0-8-8-8-9c0-6,7-8,8-8c3,0,8,4,11,4c2,0,6-1,8-5v-62H374.5zM604.5,67.5v61c1,5,5,6,8,6c2,0,8-4,10-4c6,0,9,7,9,8c0,6-8,9-9,9c-2,0-8-4-10-4c-3,0-8,1-8,5	v62h-60c-2-1-6-5-6-7c0-3,4-8,4-11c0-7-5-9-10-9c-7,0-9,4-9,9c0,3,4,8,4,11c0,2-4,7-7,7h-59v-63c-2-4-6-4-8-4c-3,0-8,4-11,4	c-6,0-8-8-8-9c0-6,7-8,8-8c3,0,8,4,11,4c2,0,6-1,8-5v-62H604.5z",
				3 : "M0,0v213h634V0H0z M86.5,67.5c4-1,9,4,9,7c0,2-4,8-4,10	c0,7,5,10,9,10c7,0,10-5,10-10c0-2-4-8-4-10c0-3,3-7,6-7h59v58c-1,3-4,6-6,6c-3,0-8-3-11-3c-9,0-10,4-10,10c0,9,4,11,10,11	c3,0,8-3,11-3c2,0,6,2,6,5v59h-141v-63c-1-4-6-4-8-4c-3,0-8,4-11,4c-6,0-8-8-8-9c0-6,7-8,8-8c3,0,8,4,11,4c2,0,7-1,8-5v-62H86.5z	 M253.5,48.5c0,3-4,8-4,11c0,2,1,8,5,8h62v58c-1,3-4,6-6,6c-3,0-8-3-11-3c-9,0-10,4-10,10c0,9,4,11,10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,0,8,4,11,4c2,0,6-1,8-5v-62h61c5-1,6-6,6-8c0-3-4-8-4-11s5-8,8-8C250.5,40.5,253.5,47.5,253.5,48.5zM374.5,67.5c4-1,9,4,9,7c0,2-4,8-4,10c0,7,4,10,9,10c7,0,10-5,10-10c0-2-4-8-4-10c0-3,3-7,6-7h59v58c-1,3-4,6-6,6c-3,0-8-3-11-3	c-9,0-10,4-10,10c0,9,4,11,10,11c3,0,8-3,11-3c2,0,6,2,6,5v59h-141v-63c-2-4-6-4-8-4c-3,0-8,4-11,4c-6,0-8-8-8-9c0-6,7-8,8-8c3,0,8,4,11,4c2,0,6-1,8-5v-62H374.5z"
			},
			decorate : function(shapeNum) {
				shapeNum = shapeNum || 1;
				var shape = new ictinus.Shape(this.coords[shapeNum]);
				
				$("div.ictinus shape").hide().eq(":nth-child(" + (shapeNum + 1) + ")").show(); //FIX for IE
				shape.decorate(this.img);
			}
		};
		
		puzzle.decorate();
		
		$("#puzzleoffMap area").click(function() {
			var shapeNum = $(this).attr("rel");
			puzzle.decorate(shapeNum);
		});
	}
});

$(window).resize(function() {
	news_titles_resize();
});
