
// todo list

// IE
// DONE Menu Items Fade
// DONE Menu Dropdown Background
// DONE ListItem Shadows 
// TODO ListView Folding -> update jquery for IE
// DONE Content Shadows (both)
// DONE BoardMember photo dropshadow
// DONE IE Galleri og lightbox
// DONE Footer højere index

// Design
// TODO Project Category List-view
// TODO Project specific category list-view
// DONE Board & Teammembers list-view
// TODO BUG Specific Team Show (example: http://localhost/teams/Team-type-1)

// Functionality
// SEMI FP-Background 'mathias style'
// DONE Google Maps
// TODO YT player


/**
 * Tekst Array
 * 
 */
  
var text = new Array();
text['en'] = new Array(),
text['zh-hans'] = new Array();

text['en']['readmore'] = "Read more";
text['en']['readless'] = "Read less";
text['en']['close'] = "Close";
text['en']['clicktoenlarge'] = 'Enlarge Photo';

text['zh-hans']['readmore'] = "更多";
text['zh-hans']['readless'] = "收起";
text['zh-hans']['close'] = "关闭";
text['zh-hans']['clicktoenlarge'] = '看大图';

 
var lang = text[lang];
/*lang['readmore'] = "Read more";
lang['readless'] = "Read less";
lang['close'] = "Close";
lang['clicktoenlarge'] = 'Enlarge Photo';*/



// http://portmanholdings.com/

/**
 * Portman Holdings, Template Script
 * 
 */
$(function() 
{
	// jQuery, DOM Ready
	
	
	
	
	/**
	 * Frontpage - Slideshow
	 * 
	 */
	$slideshow = $('.fp-ss');
	if($slideshow.length > 0) 
	{
		$slides = $slideshow.find('li.views-row');
		
		$footerNavigation = $('<div class="fp-ss-footerNavigation"><ul></ul></div>');
		$('.p-footer-container').append($footerNavigation);
		
		// Current Slide
		count = 0;
		
		/**
		 * Slide To Slide
		 */
		function slideTo(index) 
		{
			if ( index >= $slides.length) 
			{
				index = 0;
			} else if (index < 0) 
			{
				index = $slides.length-1;
			}
			
			count = index;
			
			$footerNavigation.find('a').removeClass('active');
			$footerNavigation.find('a').eq(count).addClass('active');
			
			$slides.fadeOut(100);
			$slides.eq(count).fadeIn(300);
			
			
			
			
		}
		
		$slideNext = $('<a class="ss-slideNext" href="#"></a>');
		$slidePrev = $('<a class="ss-slidePrev" href="#"></a>');
		
		$slideshow.prepend($slideNext);
		$slideshow.prepend($slidePrev);
		
		$slideNext.click(function() {
			slideTo(count+1);
			return false;
		});
		$slidePrev.click(function() {
			slideTo(count-1);
			return false;
		});
		
		
		/**
		 * Subslide'er
		 * 
		 */
		$slides.each(function(index) {
			
			var $current = $(this);
			var $slideBackground = $current.find('.fp-ss-s-background');
			
			// 'Read more' functionality
			var text = lang['readmore'];
			var readmoreAction = $('<a class="fp-ss-s-co-navigation" href="#"><span class="fp-ss-s-co-navigation-arrow">&nbsp;</span><span class="fp-ss-s-co-navigation-linkText">'+text+'</span></a>');
			readmoreAction.click(function() {
				$current.find('.fp-ss-s-co-body').slideToggle(200);
				$current.find('.fp-ss-s-co-switch').slideToggle(200);
				$(this).toggleClass('active');

				// Text Switch
				if($(this).attr('class').indexOf('active') > 0) 
				{
					$(this).find('.fp-ss-s-co-navigation-linkText').html(lang['readless']);
				}
				else 
				{
					$(this).find('.fp-ss-s-co-navigation-linkText').html(lang['readmore']);
				}
				
				return false;
			});
			
			// Hide elements
			$(this).find('.fp-ss-s-co').prepend(readmoreAction);
			$current.find('.fp-ss-s-co-body').hide();
			$current.find('.fp-ss-s-co-switch').hide();
			
			
			// Background Switch Functionality
			$current.find('.fp-ss-s-co-switch a').click(function() {
				
				$('.fp-ss-s-co-switch a').removeClass('active');
				$(this).addClass('active');
				
				var type = $(this).parent().attr('class');
				var url = $(this).attr('href');
				
				switch(type) 
				{
					case 'image':
						$current.find('.fp-ss-s-background').html('<img src="'+url+'" />');
						$(window).load();
						break;
					case 'video':
						
						$player = $('<div class="youtube-player"></div>');
						$player.youTubeEmbed(url);
						$slideBackground.html($player);
						
						break;
					case 'maps':
						break;
					default:
						url += "&output=embed";
						var map = $('<iframe class="maps" width="100%" height="100%" src="'+url+'" frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>')
						$slideBackground.html(map);
				}
				
				return false;
				
			});
			
			
			// Switch Slideshow
			var selectSlideAction = $('<a href="#"></a>');
			selectSlideAction.click(function() {
				slideTo(index);
				return false;
			});
			$footerNavigation.find('ul').append($('<li></li>').append(selectSlideAction));
			
			
			// Select Background
			$videos = $current.find('li.video');
			if($videos.length > 0) 
			{
				url = $videos.eq(0).find('a').attr('href');
				$player = $('<div class="youtube-player"></div>');
				$player.youTubeEmbed(url);
				$slideBackground.html($player);
			} 
			else 
			{
				// Nothing, keep the image as background.
			}
			
		});
		
		// First Slide
		slideTo(0);
		
		
		/**
		 * Frontapage - Background Resize
		 */
		$(window).load(function() {   

	        var theWindow        = $(window),
	            $bg              = $('.fp-ss-s-background img'),
	            aspectRatio      = $bg.width() / $bg.height();

	        function resizeBg() {

	                if ( (theWindow.width() / theWindow.height()) < aspectRatio ) {
	                    $bg
	                        .removeClass()
	                        .addClass('bgheight');
	                } else {
	                    $bg
	                        .removeClass()
	                        .addClass('bgwidth');
	                }

	        }

	        theWindow.resize(function() {
	                resizeBg();
	        }).trigger("resize");

	   });
		
		
		
	}
	
	
	
	
	
	
	
	/**
	 * Case Page - Gallery
	 * 
	 * 
	 */
	$CasePageGalleryList = $('.basic-page-content-case-gallery');
	if($CasePageGalleryList.length > 0) 
	{
		var galleryList = $CasePageGalleryList.find('li');
		var count=0;
		
		
		galleryList.each(function(index) {
			$(this).attr('rel',index);
		});
		
		// Actions
		text = lang['clicktoenlarge'];
		var actionPrevious = $('<a href="#" class="action pre">&nbsp;</a>');
		var actionNext =  $('<a href="#" class="action next">&nbsp;</a>');
		var actionZoom =  $('<a href="#" class="action zoom"></a>');
		
		// Slide To Slide
		function caseGallerySlideTo(index) {
			
			if ( index >= galleryList.length)
			{
				index = 0;
			} else if (index < 0) 
			{
				index = galleryList.length-1;
			}
			
			count = index;
			
			galleryList.hide();
			galleryList.eq(index).fadeIn(200);
			
			//actionZoom.attr('href',galleryList.eq(count).find('a').attr('href');)
			
			var currenturl = galleryList.eq(count).find('a').attr('href');
			
			actionZoom.attr('href',currenturl);
			
		}
		
		// Append Actions to buttons
		actionPrevious.click(function() {
			caseGallerySlideTo(count-1);
			return false;
		});
		
		actionNext.click(function() {
			caseGallerySlideTo(count+1);
			return false;
		});
		
		actionZoom.fancybox();
		actionZoom.append('<span>'+text+'</span>');

		
		// Attach the first url
		var currenturl = galleryList.eq(count).find('a').attr('href');
		actionZoom.attr('href',currenturl);
		
		// Write the HTML
		var html = $('<div class="basic-page-content-case-gallery-navigation"></div>');
		
		html.append(actionPrevious);
		html.append(actionZoom);
		html.append(actionNext);
		
		$CasePageGalleryList.prepend(html);
	}
	

	
	
	
	
	
	
	
	/**
	 * List - Biography Folding List
	 * 
	 */
	$ListBiographyFoldingList = $('.list-view.biography.folding li');
	if($ListBiographyFoldingList.length > 0) 
	{
		$ListBiographyFoldingList.each(function() {
			
			var $current = $(this);
			
			var text = lang['readmore'];
			var text_close = lang['close'];
			
			var readmoreAction = $('<a href="#" class="list-view-li-header"><span class="list-view-li-header-arrow">&nbsp;</span><span class="list-view-li-header-linkText">'+text+'</span></a>');
			
			readmoreAction.click(function() {
				
				$current.find('.list-view-li-content-moreContent').slideToggle();
				
				if($current.attr('class').indexOf('active') > 0) 
				{
					$current.find('.list-view-li-container').animate({
					    height: '360px'
					}, 200);
					
					$(this).find('.list-view-li-header-linkText').html(text);
					
					// Focus on the $current
					$current.focus();
					
				}
				else 
				{
					$current.find('.list-view-li-container').animate({
					    height: '741px'
					  }, 200);
					$(this).find('.list-view-li-header-linkText').html(text_close);
				}
				
				
				$current.toggleClass('active');
				
				$current.focus();
				
				
				
				return false;
			});
			
			$(this).find('.list-view-li-container').prepend(readmoreAction);
			
		});	
	}
	
	
	
	
	
});



