/******************************************************************************************************
* iPad
******************************************************************************************************/

$(document).ready(function() {

	

	window.ipad   = navigator.userAgent.match(/iPad/i) != null;
	if (window.ipad) {

		$(".link-nav li a").mouseover(function () {
			$(this).siblings().hide();
			$("#content").removeClass("content-height");
		});


	} else {

		$(".link-nav li a").mouseover(function () {
			$(this).siblings().stop().show();
			// /$("#content").removeClass("content-height");
		});

		$(".link-nav li a").mouseleave(function () {
			$(this).siblings("p").hide();
			$(this).parent().stop().animate({"height": "45px"}, "fast");
			//$("#content").addClass("content-height");
		});

		$(".link-nav li.nav_see-change a").mouseenter(function () {
			$(this).parent().stop().animate({"height": "108px"}, "slow");
		});
		$(".link-nav li.nav_implement-change a").mouseenter(function () {
			$(this).parent().stop().animate({"height": "123px"}, "slow");
		});
		$(".link-nav li.nav_why-wait a").mouseenter(function () {
			$(this).parent().stop().animate({"height": "90px"}, "slow");
		});

		$('.link-nav li p').hide();

		$("#scroll-nav li").mouseenter(function () {
			$("#scroll-nav p").hide()
			$(this).children("p").fadeIn();
			$(this).children().children().fadeIn();
			$("#scroll-nav li p").removeClass("hidden");

			$("#scroll-nav li .selected").siblings().addClass("hidden");
		});

		$("#scroll-nav li").click(function () {
			$("#scroll-nav li a").removeClass("hidden");
		});

		$("#scroll-nav li").mouseleave(function () {
			$("#scroll-nav p").hide()
			$(this).children("p").hide()
		});
	}/* endif */


/******************************************************************************************************
* Make things scroll
******************************************************************************************************/

$('.scroll a').click(function () {

	$('#visual').animate({marginTop: "0px"}, 400 );
	$(".level1").hide();
	$(".level0 .content-btn-hor").show();
	$(".level0 .content-btn").show();
	$("#scroll-nav p").hide();
	$(".level1 .content-btn").hide();
	$(".level0 .rotation-nav").show();

	$(".next").show();// for ie 7
	$(".prev").show();// for ie 7

	$("#pie-see").show(); // for ie 7
	$("#pie-implement").show(); // for ie 7

	$(".news-items").animate({width:'345px'}, 500);
	$(".full-content").hide();
	$(".news-item-title").show();
	$(".more").show();
	$(".less").hide();
	$(".news-items").show();


	$(".level0").animate({marginTop: "0px"}, 500 );

	// scroll pages
	$('#content').scrollTo($(this).attr('href'), 800);
	$('#visual').scrollTo($(this).attr('href'), 1200);

	// scroll nav active state
	$('#scroll-nav li a').removeClass('selected');
	$('#scroll-nav li a[href=' + $(this).attr('href') + ']').addClass('selected');
	
	// Set window.location
	console.log(window.location.pathname);
	window.location.hash = $(this).attr('href');

	return false;

});


/******************************************************************************************************
* Hide this
******************************************************************************************************/
	$(".full-content").hide();
	$(".less").hide();

/******************************************************************************************************
* News page 
******************************************************************************************************/

$("#news-box a.open").toggle(function () {
	$(".news-items").hide();
	$(this).parent().show().animate({width:'710px'}, 500);
	$(".news-item-title").hide();
	$(".full-content").show();
	$(".more").hide();
	$(".less").show();
}, function () {
	$(this).parent().animate({width:'345px'}, 500);
	$(".full-content").hide();
	$(".news-item-title").show();
	$(".more").show();
	$(".less").hide();
	$(".news-items").show();

});

/******************************************************************************************************
* show & hide levels
******************************************************************************************************/ 
	
$(".level1").hide();
$(".level2").hide();

/******************************************************************************************************
* show FIRST page
******************************************************************************************************/   
$('.scroll-to-1').click(function () {


	$(".level2").hide();

	$("#pie-see").hide(); // for ie 7
	$("#pie-implement").hide(); // for ie 7


	$(".next").hide();// for ie 7
	$(".prev").hide();// for ie 7        

	$("#visual").animate({marginTop: "-1000px"}, 400 );
	$(".subcontent").fadeIn();

	$(".level0").animate({marginTop: "-400px"}, 500 );
	$(this).parent().siblings().show();

	$(".level1 .content-btn").show();
	$(".level1 h3").show();

	$("#content").removeClass("content-height");

	$(".level0 .content-btn-hor").hide();
	$(".level0 .content-btn").hide();
	$(".level0 .rotation-nav").hide();

	$("#downloads").show();
	$("#quotes").show();
	$("#pers").show();
	$("#tweets").show();

});

// show middle page    
$('#link-barometer').click(function () {
	$("#new-customer").hide();
	$("#barometer").show();
});

// show middle page    
$('#link-new-customer').click(function () {
	$("#new-customer").show();
	$("#barometer").hide();
});

/******************************************************************************************************
* show SECOND page
******************************************************************************************************/

$('.scroll-to-top').click(function () {
	//$("#visual").show();
	$(".level0").animate({marginTop: "0px"}, 500 );
	$(this).siblings().hide();

	$(".level1 .content-btn").hide();

	$(".level0 .content-btn-hor").show();
	$(".level0 .content-btn").show();
	$(".level0 .rotation-nav").show();
	
	$("#content").addClass("content-height");
	

	$('#visual').animate({marginTop: "0px"}, 400 );

	$("#pie-see").show(); // for ie 7
	$("#pie-implement").show(); // for ie 7

	$(".next").show();// for ie 7
	$(".prev").show();// for ie 7

});

/******************************************************************************************************
* Make content bigger
******************************************************************************************************/
 
	$("#scroll-nav li a:not(.bigger-height)").click(function () {        
		$("#content").addClass("content-height").removeClass("big-content");
	});

	$("#scroll-nav .bigger-height a").click(function () {        
		$(this).parent().parent().parent().parent().siblings().removeClass("content-height").addClass("big-content");
	});

/******************************************************************************************************
* navigation homepage
******************************************************************************************************/
$(".rotation-nav-first a").toggle(function () {
	$(".rotation-nav .slideshow").show();
	$(".rotation-nav-second").hide();
}, function () {
	$(".rotation-nav .slideshow").hide();
	$(".rotation-nav-second").show();
});

//$(".rotation-nav-first a").mouseleave(function () {
//	$(".rotation-nav .slideshow").hide();
//	$(".rotation-nav-second").show();
//});

$(".rotation-nav .slideshow").hide()


/******************************************************************************************************
* show & hide page titles in navigation
******************************************************************************************************/
	$("#scroll-nav p").hide()
   
/******************************************************************************************************
* show & hide pie txt (tip)
******************************************************************************************************/    
    
    $(".tip").hide();
    
   	$("#pie-see li").mouseenter(function () {
        $(this).children(".tip").fadeIn("slow");
    }); 
    
    $("#pie-see li").mouseleave(function () {
        $(this).children(".tip").fadeOut("fast");
    }); 
    
     $("#pie-implement li").mouseenter(function () {
        $(this).children(".tip").fadeIn("slow");
    }); 
    
    $("#pie-implement li").mouseleave(function () {
        $(this).children(".tip").fadeOut("fast");
    });
       
        
/******************************************************************************************************
* Common things
******************************************************************************************************/    
    
	$('.inputfield').clearField();
	$('.level1').hide();
	
	
/******************************************************************************************************
* scroll to the next page
******************************************************************************************************/  

	$(".next").click(function () {
		id = $(this).closest('.page').attr('id');
		$('#scroll-nav li a[href=#' + id + ']').closest('li').next().find('a').click();
	});
    
    
/******************************************************************************************************
* scroll to the prev page
******************************************************************************************************/  

	$(".prev").click(function () {
		id = $(this).closest('.page').attr('id');
		$('#scroll-nav li a[href=#' + id + ']').closest('li').prev().find('a').click();
	});
                
/******************************************************************************************************
* Slideshow
******************************************************************************************************/

	$('.slideshow').cycle({
			fx:    'fade', 
	    speed:  500
	});

// end //

	// Go to slide on page load when # in url
	if (window.location.hash != ""){
		$('#header.scroll a[href='+window.location.hash+']').first().click();
	};
});







