$(document).ready(function() {
	
	$('html').removeClass('no-js');
	
	// Fade in cufon-ed text
	var $cufoned = $('.dynamicImage h2, #contentHeader h1, #contentHeaderWide h1, .nav li a, .stockValue, .businessColumn h2, .rightCol .panel h3, .featuredColumn h3, .newsColumn h3, .flagshipColumn h3, h1, h2, h3, h4, h5, h6');
	if (!$.browser.msie) { $cufoned.delay(250).show(); }
	else setTimeout(function() { $cufoned.hide().delay(750).show(); });
		
	$('.level2').mouseover(function(){
		$(this).parent().addClass('activeSub');
		return false;
	})
	
	$('.level2').mouseout(function(){
		$(this).parent().removeClass('activeSub');
		return false;
	})
	
	$('.readMore').click(function(){
		$(this).siblings('.moreInfo').slideToggle();
		$(this).hide();
		return false;
	})
	
	$('.moreInfo').click(function(){
		$(this).slideToggle();
		$(this).siblings('.readMore').delay(500).fadeIn();
		return false;
	})
	
	$('.businessLocation').click(function(){
		if( $(this).siblings('.additionalInfo').is(':hidden') ) { //If immediate next container is closed...
			$(this).parent().removeClass('active').find('.additionalInfo').slideUp(); //Remove all "active" state and slide up the immediate next container
			$(this).parent().toggleClass('active').find('.additionalInfo').slideDown(); //Add "active" state to clicked trigger and slide down the immediate next container
		}
		else {
			$(this).siblings('.additionalInfo').slideUp().parent().removeClass('active');
		}
		return false; //Prevent the browser jump to the link anchor
	})
	
//	$('#listView, #mapView').click(function(){
//		$('#listViewContent').toggle();
//		$('#mapViewContent').toggle();
//		$('#listView a, #mapView a').toggleClass('active');
//		return false;
//	})

    $('#mapView').click(function () {
        $('#mapViewContent').show();
        $('#listViewContent').hide();
        if (!$('#mapView a').is('.active')) {
            $('#listView a, #mapView a').toggleClass('active');
        }
        return false;
    })


    $('#listView').click(function () {
        $('#listViewContent').show();
        $('#mapViewContent').hide();
        if (!$('#listView a').is('.active')) {
            $('#listView a, #mapView a').toggleClass('active');
            }
        return false;
    })
    
    if ($("#mapViewContent").length && window.location.href.search(/\?area=/) > -1) $('#mapView').trigger("click");

	$('.topicListCol li').click(function(){
		$('.topicListCol li').removeClass('active');
		$(this).addClass('active');
		currentItem = $(this).index();
		$('.answerCol div').hide();
		$('.answerCol div').eq(currentItem).show();
		return false;
	})
	
	$.fn.clearDefault = function(){
		return this.each(function(){
			var default_value = $(this).val();
			$(this).focus(function(){
				if ($(this).val() == default_value) $(this).val("");
			});
			$(this).blur(function(){
				if ($(this).val() == "") $(this).val(default_value);
			});
		});
	};
	
	$('#search, #subscribe, .enquiryForm input, .enquiryForm textarea').clearDefault();
	 
	if($('.rightCol').has('div.extra')) {
		$('div.extra')
			.hide()
			.parent()
			.append('<a class="more">READ MORE</a>')		
	}
	$('.rightCol').click(function(){
		$(this).find('.extra').stop(true, true).slideToggle('slow');
		if($(this).children('.more').text() == 'READ MORE') {
			$(this).children('.more').text('COLLAPSE')
		}
		else {
			$(this).children('.more').text('READ MORE')
		}	
	});

});

