﻿/// <reference path="jquery-1.5.2-vsdoc.js" />
jQuery(function ($) {

	$('#footer .content .mask:eq(0)').attr('scrollHeight')

	//.wrapInner('<div class="mask"><div class="maskInner" /></div>').children(':first'),

	var 
        footer = $('#footer .content .mask:eq(0)'), //.wrapInner('<div class="box"><div class="mask" /></div>').find('.mask'),
        footerInitialHeight = footer.height(),
        footerScrollHeight = footer.prop('scrollHeight'),
        footerToggle = 1,
        map = $('#footer .content .map'),
        mapInitialHeight = map.height(),
        mapScrollHeight = map.prop('scrollHeight'),
        mapToggle = 1
    ;

	$('<button class="footerToggle"></button>').click(function (event) {
		$(this).toggleClass('footerToggle_open');
		event.preventDefault();
		$('#footer').toggleClass('footer-fixed');
		//console.log(footerInitialHeight + " - " + footerScrollHeight);

		//console.log(footerInitialHeight + " - " + footerScrollHeight);

		footer.animate(
            { "height": (footerToggle = 1 - footerToggle) ? footerInitialHeight : footerScrollHeight },
            { duration: "slow" }
        );

		map.animate(
            { "height": (mapToggle = 1 - mapToggle) ? mapInitialHeight : mapScrollHeight },
            { duration: "slow" }
        );
	}).insertBefore(footer);



	//scrollable
	// C2 - Had to stop this just attaching to everything as some scrollers like twitter have dynamic content and won't work properly if this is applied before the content is rendered

	// Homepage
	// { circular: true }
	$('.hero .scrollable').scrollable().autoscroll({ autoplay: true, autopause: true, interval: 8000 }).navigator();

	// News
	$('.latestNews .scrollable').scrollable(); 	//{ circular: true }

	// Content pages
	$('#scrollable-internal').scrollable().navigator(); 	//{ circular: true }
	//$('#scrollable-internal').navigator();

	//if ($.browser.msie) {
	//	$('.hero .scrollable')
	//}


	//end scrollable


	$('#nav li.n1').hoverIntent(function () {
		$('li.n1 .work').slideDown();
	},
    function () {
    	$('li.n1 .work').slideUp();
    });


	if ($(".accordion-wrapper").length) {
		applyAccordion();
	}
});

function applyAccordion() {
    // product data accordion 
    if ($(".accordion-wrapper").length) {
	$(".accordion-data").hide();

	$(".accordion-title").each(function() {
	    $(this).html('<a href="#" class="closedExpand">' + $(this).text() + '</a>');
	});

	$(".accordion-wrapper .accordion-title a").click(function() {
	    //cycle through all accordion data a close any open
	    $(".accordion-wrapper .accordion-data").each(function() {
		  //console.log($(this).css('display'));
		  if ($(this).css('display') == 'block') {
			  $(this).slideToggle();
		  } 
	    });
	    // reset all the link css class
	    $(".accordion-wrapper .accordion-title a").each(function() {
			$(this).removeClass('expand');
			$(this).parent('.accordion-title').parent('.accordion-wrapper').removeClass('active');
	    });
	    // set the current a class
	    if ($(this).parent(".accordion-title").length) {
			$(this).toggleClass("expand");
	    }
	    // open this data
		$(this).parent('.accordion-title').parent('.accordion-wrapper').addClass('active');
	    $(this).parent().next().slideToggle();
	    return false;
	});
	// set the first to default open
	$(".accordion-wrapper .accordion-title.first a").addClass("expand");
	$(".accordion-wrapper .accordion-title.first").next().slideToggle();
    }
}



