var loading = false;

function ajaxpage(url){
	//call url
	$.ajax({
	  type: "GET",
	  url: url,
	  success: function(data){
		//get content
		var content = /<!--start content-->([\s\S]*)<!--end content-->/im.exec(data);
		var title = /<title>([\s\S]*)<\/title>/im.exec(data);
		content = content[1];
		title = title[1];
		if(content=='') alert('content not found. please try again.');
		//change content
		else {
				$('.content').html('');
				$(".body").animate({
				  width: 797
				}, 500);
				$(".middle").animate({
				  width: 492
				}, 500, '', function(){
					$('.content').html(content);
					document.title = title;
					$('.footer').show(); 
					$('.left .switch, .right .switch').show();
					loading = false;
				})
			}
		},
	  error: function(a, b, c){
			window.location=url;
		}
	});
}

function pausecomp(millis)
{
	var date = new Date();
	var curDate = null;

	do { curDate = new Date(); }
	while(curDate-date < millis);
}

function leftswitch(){
	$('.left .switch a').click(function(){
		if($('.left').css('margin-right')=='0px'){
			$('.left .switch').hide();
			$('.left').css('z-index', '-1000');
			$(".left").animate({
				  marginRight: '-114px', marginLeft: '114px'
			}, 500, false, function(){
				$('.left').css('z-index', '0');
				$('.left .switch img').attr('src', 'images/switch_left.gif');
				$('.left .switch').show();
			});
		}
		else{
			$('.left .switch').hide();
			$('.left').css('z-index', '-1000');
			$(".left").animate({
				  marginRight: '0px', marginLeft: '0px'
			}, 500, false, function(){
				$('.left .switch img').attr('src', 'images/switch_right.gif');
				$('.left .switch').show();
				$('.left').css('z-index', '0');
			});
		}
		return false;
	});
}

function leftswitch_ie6(){
	$('.left .switch a').click(function(){
		if($('.left').css('margin-right')=='0px'){
			$('.left .switch').hide();
			$('.left').css('z-index', '-1000');
			$(".left").animate({
				  marginRight: '-114px', marginLeft: '114px'
			}, 500, false, function(){
				$('.left').css('z-index', '0');
				$('.left .switch img').attr('src', 'images/switch_left.gif');
				$('.left .switch').show();
			});
		}
		else{
			$('.left .switch').hide();
			$('.left').css('z-index', '-1000');
			$(".left").animate({
				  marginRight: '0px', marginLeft: '0px'
			}, 500, false, function(){
				$('.left .switch img').attr('src', 'images/switch_right.gif');
				$('.left .switch').show();
				$('.left').css('z-index', '0');
			});
		}
		return false;
	});
}

function rightswitch(){
	$('.right .switch a').click(function(){
		if($('.right').css('margin-left')=='0px'){
			$('.right').css('z-index', '-1000');
			$('.right .switch').hide();
			$(".right").animate({
				  marginLeft: '-161px'
			}, 500, false, function(){
				$('.right_left, .right_right').hide();
				$('.right').css('z-index', '0');
				$('.right .switch img').attr('src', 'images/switch2_right.gif');
				$('.right .switch').show();
			});
		}
		else{
			$('.right .switch').hide();
			$('.right').css('z-index', '-1000');
			$('.right_left, .right_right').show();
			$(".right").animate({
				  marginLeft: '0px'
			}, 500, false, function(){
				$('.right .switch img').attr('src', 'images/switch2_left.gif');
				$('.right .switch').show();
				$('.right').css('z-index', '0');
			});
		}
		return false;
	});
}

function rightswitch_ie6(){
	$('.right .switch a').click(function(){
		if($('.right').css('margin-left')=='0px'){
			$('.right').css('z-index', '-1000');
			$('.right .switch').hide();
			$(".right").animate({
				  marginLeft: '-136px'
			}, 500, false, function(){
				$('.right_left, .right_right').hide();
				$('.right').css('z-index', '0');
				$('.right .switch img').attr('src', 'images/switch2_right.gif');
				$('.right .switch').show();
			});
		}
		else{
			$('.right .switch').hide();
			$('.right').css('z-index', '-1000');
			$('.right_left, .right_right').show();
			$(".right").animate({
				  marginLeft: '0px'
			}, 500, false, function(){
				$('.right .switch img').attr('src', 'images/switch2_left.gif');
				$('.right .switch').show();
				$('.right').css('z-index', '0');
			});
		}
		return false;
	});
}

function ajaxclick(){
	$('.left ul li a, .portfolio a').click(function(){
		if(loading==true) return false;
		else loading=true;
		url = $(this).attr('href');
		$('.left .switch, .right .switch').hide();
		$('.content').html('');
		$('.footer').hide();
		$('a').click(function(){return false;});
		$(".middle").animate({
		  width: 100
		}, 500);
		$(".body").animate({
		  width: 405
		}, 500, '', function(){
			$('.content').html('<div style="text-align: center; margin-top: 100px;"><img src="images/loading.gif" alt="" /></div>');
			setTimeout("ajaxpage(url)",1250);
		});
		
		return false;
	});
}