// JavaScript Document
var currentPosition = 0;
var slideWidth = 1024;
var slides = $('.slide');
var slideLth = 4;
var slideIndex = 0;
var goToPage = '';
var timerId = 0;

$(document).ready(function(){

//$('#myMainFooter').hide();
//$("#ltGreyDivider").hide();
//$("#dkGreyDivider").hide();

//$("#myMainBody").css('height','0px');
//$("#myMainBody").css('overflow','hidden');
//$("#myMainContent").css('height','0px');
//$("#myMainContent").css('overflow','hidden');
//$("#myMainPortfolio").css('height','0px');
//$("#myMainPortfolio").css('overflow','hidden');



setAni();

timerId = window.setInterval(function() {
 $(".circleSelected").removeClass('circleSelected').addClass('circle');
	slideIndex = slideIndex + 1;
	if ( slideIndex < 0 ) { slideIndex =  slideLth;}
	if ( slideIndex > slideLth ) { slideIndex =  0;}
	$('#innerSlider').animate({ 'marginLeft' : slideWidth*(-slideIndex)  }, 750 );
	$("#slideControls a:eq("+slideIndex+")").removeClass('circle').addClass('circleSelected');
},  6500);

});

$(window).load(function () {
 // openIndexPage();

});
 
function setAni() {

$("#myMainBody").touchwipe({
	
    wipeLeft: function() { 
	clearInterval(timerId);
	$(".circleSelected").removeClass('circleSelected').addClass('circle');
	slideIndex = slideIndex + 1;
	if ( slideIndex < 0 ) { slideIndex =  slideLth;}
	if ( slideIndex > slideLth ) { slideIndex =  0;}
	$('#innerSlider').animate({ 'marginLeft' : slideWidth*(-slideIndex)  }, 750 );
	$("#slideControls a:eq("+slideIndex+")").removeClass('circle').addClass('circleSelected');
	
	},
    wipeRight: function() {
		clearInterval(timerId); 
	$(".circleSelected").removeClass('circleSelected').addClass('circle');
	slideIndex = slideIndex - 1 ;
	if ( slideIndex < 0 ) { slideIndex =  slideLth;}
	if ( slideIndex > slideLth ) { slideIndex =  0;}
	$('#innerSlider').animate({ 'marginLeft' : slideWidth*(-slideIndex)  }, 750 );
	$("#slideControls a:eq("+slideIndex+")").removeClass('circle').addClass('circleSelected');
	}
});


	$('#slideControls a').click(function(e){
		clearInterval(timerId);
		slideIndex= $("#slideControls a").index(this);	 
		$('#innerSlider').animate({ 'marginLeft' : slideWidth*(-slideIndex)  }, 750 );		
		$(".circleSelected").removeClass('circleSelected').addClass('circle');
		$("#slideControls a:eq("+slideIndex+")").removeClass('circle').addClass('circleSelected');
	
	return false;
});


	$('#muggins').mouseenter(function(){    	
		$('#op-chat').animate({ 'opacity' : 1 }, 500 );
	return false;
	});

	$('#muggins').mouseleave(function(){  	 
		$('#op-chat').animate({ 'opacity' : 0 }, 500 );	
	return false;
	});


$('div a').click( function(e) {
	var local = true;
	goToPage = $(this).attr("href");
	if ( goToPage.substring(0,4) == 'tel:' ) { local = false; }
	if ( goToPage.substring(0,7) == 'mailto:' ) { local = false; }
	if ( goToPage.substring(0,7) == 'http://' ) { local = false; }
	if ( goToPage == '#' ) { local = false; }

	if ( local == true ) {
		e.preventDefault();
		//closeHidePage();
		window.location.href = goToPage; 
	}
});
	
	
}
 
function openIndexPage() {
	
//$('#myMainFooter').show('slide', { direction: 'up' }, 250 , function() {   
//	$("#myMainPortfolio").animate({ height: '380px' }, 350, function() {
//			$("#myMainContent").animate({ height: '600px' }, 450, function() {
//				$("#myMainBody").animate({ height: '450px' }, 500);
//			});					   
//	});
//});

$('#myMainFooter').show('slide', { direction: 'up' }, 250 );
$("#myMainPortfolio").animate({ height: '380px' }, 350);
$("#myMainContent").animate({ height: '600px' }, 500); 
$("#myMainBody").animate({ height: '450px' }, 750);

//$("#myMainBody").show('slide', { direction: 'up' }, 750);
//$("#myMainContent").show('slide', { direction: 'up' }, 1000);
//$("#myMainPortfolio").show('slide', { direction: 'up' }, 1250);
//$('#myMainFooter').show('slide', { direction: 'up' }, 1500);
$("#ltGreyDivider").show();
$("#dkGreyDivider").show();
}

function closePage() {
$('body').animate({ scrollTop: $("#myTopHeader").offset().top }, 500 , function() {
    // Animation complete.
	closeHidePage();
});


//$("#myMainBody").hide('slide', { direction: 'up' }, 1200);
//$("#myMainContent").hide('slide', { direction: 'up' }, 900);
//$("#myMainPortfolio").hide('slide', { direction: 'up' }, 600);
//$('#myMainFooter').hide('slide', { direction: 'up' }, 300);
	
}

function closeHidePage() {
$("#ltGreyDivider").hide();
$("#dkGreyDivider").hide();

		 
$('#myMainFooter').hide('slide', { direction: 'up' }, 250 );
$("#myMainPortfolio").animate({ height: '0px' }, 350);
$("#myMainContent").animate({ height: '0px' }, 500); 

$("#myMainBody").animate({ height: '0px' }, 750, function () {
		
		window.location.href = goToPage; 
});


		 
}
