var collectionsCarouselTab = 0;
if((jQuery.browser.msie === true) && (jQuery.browser.version == '6.0'))        
{        
	DD_belatedPNG.fix('#leftNav, img, .generalPhoto, h2, #leftNav a, #leftNav a div, .png, .printSharePR a img, #landmarkPropertiesTab, #conventionCollectionTab, #resortCollectionTab, #cityCenterTab, #developmentIntroCallout a');
}

function honeyCombClick(id)
{
	jQuery('a#hiddenClick').trigger('click');
	jQuery('#infrastructureDivs').nextPrevious({
		content: 'infrastructure',
		hiddenKey: id,
		dynamicContent: true,
		extraID: '#fancy_div'
	});
}


jQuery(function navigationUpdate()
{
	jQuery('a.leftSubNavOn').parent().prev().addClass('mainActive');
	
	if(jQuery('#leftNav a').hasClass('mainActive'))
	{
		jQuery('#leftNav a.mainActive').children().children('span').attr('class', 'activeIconOff');
	}
	
	jQuery('#leftNav a:first div').css('background-image', 'none');
	if(document.getElementById('socialMediaCallout'))
	{
		jQuery('#socialMediaCallout').prepend('<span class="bottomNavBorder"><img src="/Images/AboutOmni/aboutOmniNavDivider.png" alt="" class="png" /></span>');
	}
	else(document.getElementById('developerContactInfo'))
	{
		jQuery('.bottomNavBorder').html('');
	}	
});


jQuery(document).ready(function(){
    /********* Scroll to location *********/
    jQuery('.scrollToLocation').click(function() {
        var getHref = jQuery(this).attr('href');
        var correctAnchor = getHref.replace(/#/, '');
        var targetOffset = jQuery('#' + correctAnchor).offset().top;

        jQuery('html, body').animate({ scrollTop: targetOffset }, 500);

        return false;
    });

	//Portfolio Page
	if(!document.getElementById('currentFutureDistribution')) return false;
	jQuery('a#currentFutureDistribution').fancybox({
		'autoDimensions' : false,
		'frameWidth' : 782,
		'frameHeight' : 583,
		'padding' : 0
	});
	
	jQuery('a#caseStudies').fancybox({
		'autoDimensions' : false,
		'frameWidth' : 782,
		'frameHeight' : 610,
		'padding' : 0,
		'callbackOnShow' : function()
		{
			pagination();
			selectCaseStudy();
			nextPreviousControl();
			closeCaseStudy();
			jQuery('#fancy_div ul.caseStudyList li a').click(function(){
				jQuery('#fancy_div ul li a').removeClass('active');
				jQuery(this).addClass('active');
				
				var number_of_items = jQuery('#fancy_div ul').children().size();
				var caseStudyHolder = jQuery('.rightCaseStudies div');
				var caseStudy = jQuery(this).attr('rel');
				var caseStudyIndex = caseStudy.replace('#caseStudy', '');
				
				jQuery('.case_study').val(caseStudyIndex);
				
				var caseStudyHTML = jQuery(caseStudy).html();
				//caseStudyHolder.slideUp();
				caseStudyHolder.html(caseStudyHTML);
				//caseStudyHolder.slideDown();
				
				if(jQuery('.case_study').val() == number_of_items)
				{
					jQuery('#fancy_div a#nextItem').addClass('disabled');
					jQuery('#fancy_div a#previousItem').removeClass('disabled');
					return false;
				}
				else if(jQuery('.case_study').val() == 1)
				{
					jQuery('#fancy_div a#nextItem').removeClass('disabled');
					jQuery('#fancy_div a#previousItem').addClass('disabled');
					return false;
				}
				else
				{
					jQuery('#fancy_div a#nextItem').removeClass('disabled');
					jQuery('#fancy_div a#previousItem').removeClass('disabled');
				}
			});	
		},
		'callbackOnClose' : function()
		{
			jQuery('.rightCaseStudies').html('');
			jQuery('.rightCaseStudies').append('<div></div>');
		}
	});
	function closeCaseStudy()
	{	
		jQuery('#fancy_div #closeCaseStudy').click(function(){
			jQuery.fn.fancybox.close();
		});
	}
	
	function selectCaseStudy()
	{
		//Set hidden value for defualt case study
		jQuery('.case_study').val(1);
		jQuery('.rightCaseStudies div').html(jQuery('#caseStudy1').html());
	}
	
	
	
	function nextPreviousControl()
	{
		jQuery('#fancy_div a#nextItem').click(nextItem);
		jQuery('#fancy_div a#previousItem').click(previousItem);
	}
	
	function nextItem()
	{
		jQuery('#fancy_div a#previousItem').removeClass('disabled');
		var number_of_items = jQuery('#fancy_div ul').children().size();

		var next_content = parseInt(jQuery('.case_study').val()) + 1;
		jQuery('.case_study').val(next_content);
		next_content = '#caseStudy' + next_content;
		
		if(jQuery('.case_study').val() == parseInt(jQuery('.show_per_page').val())+ 1)
		{
			next();
		}
		
		jQuery('#fancy_div ul.caseStudyList li a').each(function(){
			if(jQuery(this).attr('rel') == next_content)
			{
				jQuery('#fancy_div ul li a').removeClass('active');
				jQuery(this).addClass('active');
			}
		});
		next_content = jQuery(next_content).html();
		jQuery('.rightCaseStudies div').html(next_content);

		if(jQuery('.case_study').val() == number_of_items)
		{
			jQuery(this).addClass('disabled');
			return false;
		}
		

	}
	
	function previousItem()
	{
		jQuery('#fancy_div a#nextItem').removeClass('disabled');
		var prev_content = parseInt(jQuery('.case_study').val()) - 1;
		jQuery('.case_study').val(prev_content);
		prev_content = '#caseStudy' + prev_content;
		
		if(jQuery('.case_study').val() <= jQuery('.show_per_page').val())
		{
			previous();
		}
		
		jQuery('#fancy_div ul.caseStudyList li a').each(function(){
			if(jQuery(this).attr('rel') == prev_content)
			{
				jQuery('#fancy_div ul li a').removeClass('active');
				jQuery(this).addClass('active');
			}
		});
		
		prev_content = jQuery(prev_content).html();
		jQuery('.rightCaseStudies div').html(prev_content);
		
		if(jQuery('.case_study').val() == 1)
		{
			jQuery(this).addClass('disabled');
			return false;
		}
	}	
	
	
	//pagination();
	function pagination()
	{
		//how much items per page to show
		var show_per_page = 10;
		//getting the amount of elements inside content div
		var number_of_items = jQuery('#fancy_div .caseStudyList').children().size();
		
		if(number_of_items < 10) return false;
		//calculate the number of pages we are going to have
		var number_of_pages = Math.ceil(number_of_items/show_per_page);

		//set the value of our hidden input fields
		jQuery('.current_page').val(0);
		jQuery('.show_per_page').val(show_per_page);

		//now when we got all we need for the navigation let's make it '

		/*
		what are we going to have in the navigation?
			- link to previous page
			- links to specific pages
			- link to next page
		*/
		var navigation_html = '<a class="previous_link" href="javascript:void(0);">&laquo;</a>';
		var current_link = 0;
		while(number_of_pages > current_link){
			navigation_html += '<a class="page_link" href="javascript:void(0)" longdesc="' + current_link +'">'+ (current_link + 1) +'</a>';
			jQuery('a.page_link').livequery('click', function(){go_to_page(jQuery(this).attr('longdesc')); } );
			current_link++;
		}
		navigation_html += '<a class="next_link" href="javascript:void(0);">&raquo;</a>';

		jQuery('a.next_link').livequery('click', next);
		jQuery('a.previous_link').livequery('click', previous);
		jQuery('.paginationHolder').html(navigation_html);

		//add active_page class to the first page link
		jQuery('#fancy_div .paginationHolder .page_link:first').addClass('active_page');
		jQuery('#fancy_div .paginationHolder .page_link:last').addClass('lastLink');

		//hide all the elements inside content div
		jQuery('#fancy_div .caseStudyList').children().css('display', 'none');
		
		jQuery('#fancy_div .caseStudyList li:last').css('border', 'none');

		//and show the first n (show_per_page) elements
		jQuery('#fancy_div .caseStudyList').children().slice(0, show_per_page).css('display', 'block');
		
		jQuery('#fancy_div .caseStudyList').children().slice(9, show_per_page).css('border-bottom', 'none');
	}
	
	function previous(){
		new_page = parseInt(jQuery('.current_page').val()) - 1;
		
		//if there is an item before the current active link run the function
		if(jQuery('#fancy_div .active_page').prev().attr('class') == 'page_link')
		{
			go_to_page(new_page);
		}

	}

	function next(){
		new_page = parseInt(jQuery('.current_page').val()) + 1;
		//if there is an item after the current active link run the function
		if(jQuery('#fancy_div .active_page').next().attr('class') == 'page_link' || jQuery('#fancy_div .active_page').next().attr('class') == 'page_link lastLink')
		{
			go_to_page(new_page);
		}

	}
	
	function go_to_page(page_num){
		//get the number of items shown per page
		var show_per_page = parseInt(jQuery('.show_per_page').val());
		//get the element number where to start the slice from
		start_from = page_num * show_per_page;
		//get the element number where to end the slice
		end_on = start_from + show_per_page;

		//hide all children elements of content div, get specific items and show them
		jQuery('#fancy_div .caseStudyList').children().css('display', 'none').slice(start_from, end_on).css('display', 'block');

		/*get the page link that has longdesc attribute of the current page and add active_page class to it
		and remove that class from previously active page link*/
		jQuery('.page_link[longdesc=' + page_num +']').addClass('active_page').siblings('.active_page').removeClass('active_page');

		//update the current page input field
		jQuery('.current_page').val(page_num);
	}
	
});
