/* Author: 

*/

 function initialize() {
    var latlng = new google.maps.LatLng(51.54672, -0.15866);
    var myOptions = {
      zoom: 14,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("google-map"),
        myOptions);

	var image = new google.maps.MarkerImage('img/map-icon.png',
      // This marker is 20 pixels wide by 32 pixels tall.
      new google.maps.Size(40, 57),
      // The origin for this image is 0,0.
      new google.maps.Point(0,0),
      // The anchor for this image is the base of the flagpole at 0,32.
      new google.maps.Point(20, 56));
      
	var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon: image
    });

    $('#full-screen-image').css('position','absolute');
 }

jQuery(function($){
	if ($('#contact').size()>0) {
		initialize();
	};

	
	/* FONT RESIZE AAA */
	
	$("#font-size span").click(function() {
		$("#font-size span").css("background-color", "#000000");
		$(this).css("background-color", "#78cacb");
		var new_size = $(this).css("font-size");
		$("body").css("font-size", new_size);
	});
	
	
	
	
	/* TRANSITION */
	
	var int = setInterval(function() {
		slideLeft();
	}, 8000);
		
	$("#transition-right").click(function() {
		slideRight();
	});
	
	$("#transition-left").click(function() {
		slideLeft();
	});
		if ($(".transition-wrapper img:first").parent('a').length > 0) {
			var obj = $(".transition-wrapper img:first").parent();
		} else {
			var obj = $(".transition-wrapper img:first");
		};
	
	function slideRight() {

		$(".transition-wrapper").append(obj);
		obj.css("left", "-961px");
		obj.animate({left: 0}, 800);
	}
	
	function slideLeft() {
		var obj = $(".transition-wrapper img:last");
		obj.animate({left: "-961px"}, 800, function() {
			$(".transition-wrapper").prepend(obj);
			obj.css("left", "0px");
		});
	}
	
	function slideLeft2() {
		$(".transition-wrapper img").each(function(i) {
			if ($(this).css("z-index") == 2) {
				var cur = $(this);
			}
		});
		cur.css("z-index", 1);
		cur.prev().css("z-index", 2);
		cur.prev().css("left", "960px");
		obj.animate({left: 0}, 800);
	}
	
	
	
	/* CONSULTATION */
	
	$("#consultation-button").click(function() {
		if ($("#consultation-form").css("display") == "none") {
			$("#consultation-form").slideDown(500);
		} else {
			
		}
	});
	
	$("#consultation-close").click(function(e) {
		e.preventDefault();
		$("#consultation-form").slideUp(500);
	});
	
		
	
	/* SEARCH */
	$(".search-box").keyup(function() {
		var search_value = $(this).val();
		if (search_value.length > 0) {
			$(this).parent().parent().find(".press-wrapper").hide();
			$(this).parent().parent().find(".press-wrapper").filter(function() {
				return $(this).attr("title").match(new RegExp(search_value, "i"));
			}).show();
		} else {
			$(this).parent().parent().find(".press-wrapper").show();
		}
	});
	
	
	
	
	/* SUBNAV & READMORE button */
	window.onhashchange = function() {
		show_correct_article();
	}
	
	/* SUBNAV */
	
	show_correct_article();
	
	
	$("#subnav a").click(function(e) {
		if($(this).hasClass('page-link'))
		{
			return true;
		}
		else
		{
			e.preventDefault();
			var new_article = $(this).attr("class");
			location.href = location.href.split("#")[0] + "#" + new_article;
			show_correct_article();
		}
	});
	
	function hide_arrows(page)
	{
		var noPages = $('.'+page+' .page').length;

		if(noPages > 1)
		{
				$('.arrow-left,.arrow-right').show();
		}
		else
		{
				$('.arrow-left,.arrow-right').hide();
		}
		
	}
	
	function show_correct_article() {
		
		if (location.href.indexOf('#') > -1) {
			var hash = location.href.split("#");
			if (hash[1].length > 0) {
				$("#articles>div").hide();
				$("#articles").css("height", "auto");
				$("#articles div." + hash[1]).show();
				$("#subnav li").removeClass("on");
				$("#subnav a." + hash[1]).parent().addClass("on");
				
				if (hash[1] == "nucalm") {
					$("#nucalm-small").hide();
				} else {
					$("#nucalm-small").show();
				}
				
				if (hash[1] == "tdtw") {
					$("#tdtw").hide();
				} else {
					$("#tdtw").show();
				}
				
				hide_arrows(hash[1]);
			} 
		} else {
			$("#articles>div").hide();
			$("#articles div.default").show();
			$("#subnav li").removeClass("on");
		}
		
		
	}
	
	$("img.quotes").click(function() {
		var new_article = $(this).attr("class");
		location.href = location.href.split("#")[0] + "#" + new_article;
		show_correct_article();
	});
	
	
	
	/* READMORE */
	$(".readmore-content").hide();
	$(".readmore-button").click(function() {
		if ($(this).parent().find(".readmore-content").css("display") == "none") {
			$(this).parent().find(".readmore-content").slideDown(500);
			$(".readmore-button").addClass("less");
			$(".readmore-button").text("show less");
		} else {
			$(this).parent().find(".readmore-content").slideUp(500);
			$(".readmore-button").removeClass("less");
			$(".readmore-button").text("show more");
		}
	});
	
	
	
	/* bottom-box TABS */
	//$("div.bottom-box-content>div").hide();
	$(".bottom-box-content>div").each(function(){
		$(this).find('.page').not(":first").hide();
	})
	
	$("div.bottom-box li").click(function() {
		open_tab($(this).parent().parent().parent(), $(this).attr("title"));
	});
	
	
	
	
	/* Alternate Box styles */
	
//	$('.testimonials .page').not(":first").hide();
//	$('.beforeafter .page').not(":first").hide();
	
	$(".bottom-box-arrows .arrow-left").click(function(e) {
		e.preventDefault();

		if ($(this).parent().parent().find('.bottom-box-content > div:visible').find('.page:visible').prev('.page').size() > 0 ) {
			$(this).parent().parent().find('.bottom-box-content > div:visible').find('.page:visible').hide().prev('.page').show();
		} else {
			$(this).parent().parent().find('.bottom-box-content > div:visible').find('.page:visible').hide();
			$(this).parent().parent().find('.bottom-box-content > div:visible').find('.page:last').show();
		};
		// if($('li[title=testimonials]').hasClass('on')) {
		// 	var selector = 'testimonials';
		// }
		// else {
		// 	var selector = 'beforeafter';
		// }
													   
		// var cur_on = 0;
		// $("." + selector + " .page").each(function(i) {
		// 	if ($(this).css("display") == "block") {
		// 		cur_on = i;
		// 	}
		// });
		// $("."+ selector + " .page").eq(cur_on).hide();
		// var next_on = cur_on - 1;
		
		// var max_size = $("."+ selector + ' .page').size() -1;
		
		// if(next_on < 0 ) {
		// 	next_on = max_size;
		// }
		
		// $("."+ selector + " .page").eq(next_on).show();
	});
	
	$(".bottom-box-arrows .arrow-right").click(function() {
		if ($(this).parent().parent().find('.bottom-box-content > div:visible').find('.page:visible').next('.page').size() > 0 ) {
			$(this).parent().parent().find('.bottom-box-content > div:visible').find('.page:visible').hide().next('.page').show();
		} else {
			$(this).parent().parent().find('.bottom-box-content > div:visible').find('.page:visible').hide();
			$(this).parent().parent().find('.bottom-box-content > div:visible').find('.page:first').show();
		};
		// if($('li[title=testimonials]').hasClass('on')) {
		// 	var selector = 'testimonials';
		// }
		// else {
		// 	var selector = 'beforeafter';
		// }												
													
		// var cur_on = 0;
		// $("."+ selector + " .page").each(function(i) {
		// 	if ($(this).css("display") == "block") {
		// 		cur_on = i;
		// 	}
		// });
		// $("."+ selector + " .page").eq(cur_on).hide();
		// var next_on = cur_on + 1;
		
		// var max_size = $("."+ selector + ' .page').size() -1;
		
		// if(next_on > max_size) {
		// 	next_on = 0;
		// }
		
		// $("."+ selector + " .page").eq(next_on).show();
	});
	
	

	function cycle(box, direction) {
		var no_of_tabs = $(box).parent().parent().find("li").size();
		var current_tab;
		$(box).parent().parent().find("li").each(function(i) {
			if ($(this).hasClass("on")) {
				current_tab = i;
			}
		});
		
		var prev_tab = current_tab + direction;
		if (prev_tab < 0) {
			prev_tab = no_of_tabs - 1;
		} else if (prev_tab >= no_of_tabs) {
			prev_tab = 0;
		}
		
		var new_tab = $(box).parent().parent().find("li").eq(prev_tab).attr("title");
		open_tab($(box).parent().parent(), new_tab);
	}


	open_tab($(".bottom-box"), "beforeafter");
	
	function open_tab(box, tab) {
		var new_tab = tab;
		box.find("div.bottom-box-content>div").hide();
		box.find("div.bottom-box-content div." + new_tab).show();
		box.find("li").removeClass("on");
		
		box.find("li").each(function(i) {
			if ($(this).attr("title") == new_tab) {
				$(this).addClass("on");
			}
		})
	}
	
	
	/* PRESS rollover */
	$(".press-rollover").hide();
	$(".press-wrapper").hover(function() {
		$(this).find(".press-rollover").show();
	}, function() {
		$(this).find(".press-rollover").hide();
	});
	

})
  

