$(document).ready(function(){
	
	var sections = $("#secondpane a");
	var loading = $("#loading_loader");
	var content = $("#content");
	var header = $("#header");
	
	$("a[rel*='external']").click(function(){
 		pageTracker._trackPageview('/outgoing/'+ $(this).attr('href'));
	});
	
	sections.click(function(){
		showLoading();
		var gName = this.name;
		switch(this.id){
			case "about":
				content.slideUp({
					complete:function(){
						content.load("content/sections.php #section_about", hideLoading);
						header.css('background-image', 'url(images/pageHeader_about.gif)');
					}
				});
				break;
			case "contact":
				content.slideUp({
					complete:function(){
						content.load("content/sections.php #section_contact", hideLoading);
						header.css('background-image', 'url(images/pageHeader_contact.gif)');
					}
				});
				break;
			case "agents":
				content.slideUp({
					complete:function(){
						content.load("content/sections.php #section_agents", hideLoading);
						header.css('background-image', 'url(images/pageHeader_contact.gif)');
					}
				});
				break;
			case "stockists":
				content.slideUp({
					complete:function(){
						content.load("content/sections.php #section_stockists", hideLoading);
						header.css('background-image', 'url(images/pageHeader_stockists.gif)');
					}
				});
				break;
			case "collection":
				content.slideUp({
					complete:function(){		
						content.load("content/sections.php?c=" + gName + " #section_collection", hideLoading);
						header.css('background-image', 'url(images/header_collectionPage.gif)');
					}
				});
				break;
			default:
				hideLoading();
				break;
		}
	});
	function showLoading(){
		loading
			.css({visibility:"visible"})
			.css({opacity:"1"})
			.css({display:"block"})
		;
	}
	function hideLoading(){
		loading.fadeTo(1000, 0);
		content.slideDown();
	};
});

function contact(in1, in2, in3){
	if(in1 == "" || in2 == "" || in3 == ""){
		alert("* required");
		return;
	}
	showLoading();
	$.post("include/contact.php", { e: in1, s: in2, q: in3 },
	   function(data){
		$("#content").slideUp({
			complete:function(){
				$("#content").load("content/sections.php #contact_thanks", hideLoading);
			}
		});
		 
	});
	function showLoading(){
		$("#loading_loader").css({visibility:"visible"}).css({opacity:"1"}).css({display:"block"});
	}
	function hideLoading(){
		$("#loading_loader").fadeTo(1000, 0);
		$("#content").slideDown();
	};
}

function mailing_list(div_id, in1)
{
	subject_id = div_id;
	data1 = document.getElementById(in1).value;
	
	AtPos = data1.indexOf("@")
	StopPos = data1.lastIndexOf(".")
	
	if (AtPos == -1 || StopPos == -1) {
		alert("Not a valid email address");
		return;
	}else if (StopPos < AtPos) {
		alert("Not a valid email address");
		return;
	}else if (StopPos - AtPos == 1) {
		alert("Not a valid email address");
		return;
	}
	
	if(data1 == "" || data1 == "your email"){
		return;
	}
	http.open("GET", "include/subscribe.php?email=" + escape(data1), true);
	
	http.onreadystatechange = handleHttpResponse;
	http.send(null)
}

subject_id = '';

function handleHttpResponse() {
	if (http.readyState == 4) {
		if (subject_id != '') {
			
			document.getElementById(subject_id).innerHTML = http.responseText;
		}
	}
}
function getHTTPObject() {
	var xmlhttp;
	/*@cc_on
	@if (@_jscript_version >= 5)
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (E) {
				xmlhttp = false;
			}
		}
	@else
	xmlhttp = false;
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
			xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
var http = getHTTPObject(); // We create the HTTP Object
