$(document).ready(function(){

	if($('.Gallery').length > 0){
		$(".Gallery .MainContent a").attr('rel', 'prettyPhoto[gallery]');
		$("a[rel^='prettyPhoto']").prettyPhoto();
	}
	
	/***
	**** Quick Login Form
	***/
	/* Initial setup */
	$.ajaxSetup ({
		cache: false
	});
	/* Is user logged in? */
	loadUrl = '/Default.aspx?pagename=partner-login';
	$.get(loadUrl,function(responseText){
		if(responseText.search('Partner') > -1){
			$('.TopWrap .Login > div').each(function(){
				if($(this).find('#LoginControl').length > 0){
					$(this).html('<p>Partner Login: You are logged in.</p>');
				}
			});
		}
	},'html');
	
	/***
	**** Meet the team page
	***/
	/* Encapsulate team members */
	$('.Team .LeftContent h2').each(function(){
		$(this).add($(this).nextUntil('h2')).wrapAll('<div class="TeamMember"></div>');
	});
	/* Seperate dialog content */
	$('.Team .TeamMember h3').each(function(i){
		$(this).add($(this).nextAll()).wrapAll('<div class="DialogContent DialogContent' + i + '"></div>');
	});
	/* Team member layout */
	$('.Team .TeamMember').each(function(i){
		// Copy image into dialog
		var newimg = $(this).find('img').clone();
		$(this).find('.DialogContent').prepend(newimg);
		newimg.attr('src', newimg.attr('src').replace('Thumbnail-','Illustrations-'));
		// Swap image and main heading
		swap($(this).find('img').parent('p'), $(this).find('h2'));
		// Add more link
		$(this).find('h2').after('<p class="More"><a href="#">Click here</a></p>');
		// Copy heading into dialog
		var newh2 = $(this).find('h2').clone();
		$(this).find('.DialogContent').prepend(newh2);
		// Dialog opener
		var dialog = $(this).find('.DialogContent');
		$(this).find('.More a').colorbox({width:'50%', href:'.DialogContent'+i, inline: true, rel:'team'});
		dialog.wrap('<div style="display:none"></div>');
	});
	
		
		$('.Header').cycle({
		fx: 'fade',
		slideExpr: 'img',
		fit:1,
		requeueOnImageNotLoaded: true,
	
});	

$('div.navigation').css({'width' : '300px', 'float' : 'left'});
				$('div.content').css('display', 'block');

				// Initially set opacity on thumbs and add
				// additional styling for hover effect on thumbs
				var onMouseOutOpacity = 0.67;
				$('#thumbs ul.thumbs li').opacityrollover({
					mouseOutOpacity:   onMouseOutOpacity,
					mouseOverOpacity:  1.0,
					fadeSpeed:         'fast',
					exemptionSelector: '.selected'
				});
	
	// Initialize Advanced Galleriffic Gallery
				var gallery = $('#thumbs').galleriffic({
					delay:                     2500,
					numThumbs:                 15,
					preloadAhead:              10,
					enableTopPager:            false,
					enableBottomPager:         false,
					maxPagesToShow:            7,
					imageContainerSel:         '#slideshow',
					controlsContainerSel:      '#controls',
					captionContainerSel:       '#caption',
					loadingContainerSel:       '#loading',
					renderSSControls:          true,
					renderNavControls:         true,
					playLinkText:              'Play Slideshow',
					pauseLinkText:             'Pause Slideshow',
					prevLinkText:              '&lsaquo; Previous Photo',
					nextLinkText:              'Next Photo &rsaquo;',
					nextPageLinkText:          'Next &rsaquo;',
					prevPageLinkText:          '&lsaquo; Prev',
					enableHistory:             false,
					autoStart:                 false,
					syncTransitions:           true,
					defaultTransitionDuration: 900,
					onSlideChange:             function(prevIndex, nextIndex) {
						// 'this' refers to the gallery, which is an extension of $('#thumbs')
						this.find('ul.thumbs').children()
							.eq(prevIndex).fadeTo('fast', onMouseOutOpacity).end()
							.eq(nextIndex).fadeTo('fast', 1.0);
					},
					onPageTransitionOut:       function(callback) {
						this.fadeTo('fast', 0.0, callback);
					},
					onPageTransitionIn:        function() {
						this.fadeTo('fast', 1.0);
					}
				});
		
	
});

/***
**** Swap 2 elements in the markup
***/
function swap(swap1, swap2){
	var swap1clone = swap1.clone(true);
	var swap2clone = swap2.clone(true);
	swap1.before(swap2clone);
	swap2.before(swap1clone);
	swap1.remove();
	swap2.remove();
}
