// JavaScript Document
$(document).ready(function () {
	var visits = getCookie('nVisits');	
	if ($("body").attr("class") == 'home') {
		if (visits){
			//intro_replay();
			glow_menu();
			glow_logo();
			toggle_contact();
			showReload();
			startSliders();
		} else 	{
			setCookie('nVisits',visits,expDate);
			loadIntro();
		}					
	} else {
		//intro_replay();
		glow_menu();
		glow_logo();
		toggle_contact();
	}					
});

function loadIntro() {
	var hasFlash = $.flash.hasVersion(10);
	if (hasFlash){
		$('#basic-modal-content').modal({
			overlayClose:true,
			opacity:100,
			overlayCss: {backgroundColor:"#252525"},
			onClose: function(dialog){ 
				glow_menu();
				glow_logo();
				toggle_contact();
				startSliders();
				showReload();
				$.modal.close(); // must call this!
		}});
		$('#fIntro').flash({
			swf: 'assets/preloader_v2.swf',
			height: 355,
			width: 1920,
			params: {
				play: true,
				wmode: 'transparent'				
			}
		});
	} else {
	}
}

function reloadIntro() {
	hideReload();
	var hasFlash = $.flash.hasVersion(10);
	if (hasFlash){
		$('#basic-modal-content').modal({
			overlayClose:true,
			opacity:100,
			overlayCss: {backgroundColor:"#252525"},
			onClose: function(dialog){ 
				showReload();
				$.modal.close(); // must call this!
		}});
		$('#fIntro').flash({
			swf: 'assets/preloader_v2.swf',
			height: 355,
			width: 1920,
			params: {
				play: true,
				wmode: 'transparent'				
			}
		});
	} else {
	}
}

function showReload() {
		$('#home #top-wrap a.replay').show();
}
function hideReload() {
		$('#home #top-wrap a.replay').hide();
}

function closeIntro(){
	$.modal.close();
}

function glow_menu(){
	$('#hnav li a').css( {opacity: 0} );
	$('#hnav li').hover(
	function () {
		$('> a',this).show().stop().animate(
			{opacity: 1}, 
			450, 
			"linear"			
		);
	},
	function () {
		var glowed = $('> a',this);
		glowed.stop().animate(
			{ opacity: 0},
			300,
			"linear"
		);
	});
}

function glow_logo(){
	$('#logo-block').hover(
	function () {
		$('> a.logo-over',this).show().stop().animate(
			{opacity: 1}, 
			450, 
			"linear"			
		);
	},
	function () {
		var glowed = $('> a.logo-over',this);
		glowed.stop().animate(
			{ opacity: 0},
			300,
			"linear"
		);
	});
}

function intro_replay() {
	
	//create tab for replay
	//$("body").	
}

/*function styleImages(){																																	//unrem
	$(".lcol img").corner("round");
	$("#inner .lcol .bodyt .big-img img").corner("0px");
}*/

function toggle_contact(){
	$('#fb a.plus').hover(function() {
		// on hovering over, find the element we want to fade *up*	
		$('#fb  .closer a').click(function(){
			$('#fb .c-box').css("display","none");
		});
		$('#fb .c-box').css("display","block");		
	});
}

function formatText(index, panel) {
  return index + "";
}

function startSliders() {
	$(function () {
		$('.anythingSlider').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: true,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 3000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 900,             // How long the slide transition takes
			hashTags: true,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "Go",             // Start text
			stopText: "Stop",               // Stop text
			navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
		});
		
		$("#slide-jump").click(function(){
			$('.anythingSlider').anythingSlider(6);
		});
	});
	
	$(function () {
		$('.arot-2').anythingSlider({
			easing: "easeInOutExpo",        // Anything other than "linear" or "swing" requires the easing plugin
			autoPlay: false,                 // This turns off the entire FUNCTIONALY, not just if it starts running or not.
			delay: 3000,                    // How long between slide transitions in AutoPlay mode
			startStopped: false,            // If autoPlay is on, this can force it to start stopped
			animationTime: 500,             // How long the slide transition takes
			hashTags: false,                 // Should links change the hashtag in the URL?
			buildNavigation: true,          // If true, builds and list of anchor links to link to each slide
			pauseOnHover: true,             // If true, and autoPlay is enabled, the show will pause on hover
			startText: "",             // Start text
			stopText: "",               // Stop text
			navigationFormatter: formatText       // Details at the top of the file on this use (advanced use)
		});
		$("#slide-jump").click(function(){
			$('.arot-2').anythingSlider(6);
		});
	});
}

// set, get, and remove cookie stuff ****

var expDate = new Date();
expDate.setTime(expDate.getTime()+365*24*60*60*1000); // one year

function deleteCookie(isName){
 
	if (getCookie(isName))
		{
		 document.cookie = isName + "="+ "; expires=Thu, 01-Jan-70 00:00:01 GMT";
		}
}

function setCookie(isName,isValue,dExpires){
		 
	document.cookie = isName+"="+isValue+";expires="+dExpires.toGMTString();
}

function getCookie(isName){

	var cookieStr = document.cookie;
	var startSlice = cookieStr.indexOf(isName+"=");
	if (startSlice == -1){return false}
	var endSlice = cookieStr.indexOf(";",startSlice+1)
	if (endSlice == -1){endSlice = cookieStr.length}
	var isValue = cookieStr.substring(startSlice,endSlice).replace(/^.+\=/,"");
	return isValue;
}
