
var current_loc_on = true;
var current_cat_on = true;


function navHighlight() {
	if($(this).parent().hasClass("current_loc") && (current_loc_on==true)) {
		$('ul#navigation > li > a').siblings().each(function () {
		  clearTimeout($(this).parent().children().attr("hoverIntent_t"));
		});
		
	} else if($(this).parent().hasClass("current_cat") && (current_cat_on==true)) {
		$('ul#navigation > li > a').siblings().each(function () {
		  clearTimeout($(this).parent().children().attr("hoverIntent_t"));
		});
		
	} else if($(this).parent().hasClass("current_loc") && (current_loc_on==false)) {
		$('ul#navigation > li > a').siblings().each(function () {
		  clearTimeout($(this).parent().children().attr("hoverIntent_t"));
		});
		$(this).css('background-position', '0px -40px');
		$('ul#navigation > li > a').animate({backgroundPosition: '0px -40px'}, 'fast');
		$('ul#navigation > li > a').find('span').animate({backgroundPosition: '0px -40px'}, 'fast');
		$('ul#navigation > li.current_loc > a').css({color: '#5c6f7c'});
		$(this).find('span').css('background-position', '0px -40px');
		$(this).animate({backgroundPosition: '0px 0px'}, 'fast');
		$(this).find('span').animate({backgroundPosition: '0px 0px'}, 'fast');
		$('#navigation li ul').animate({marginTop: '-50px'}, 'fast');
		$(this).parent().find('ul').animate({marginTop: '-12px'}, 'fast');
		current_loc_on = true;
		
	} else if($(this).parent().hasClass("current_cat") && (current_cat_on==false)) {
		$('ul#navigation > li > a').siblings().each(function () {
		  clearTimeout($(this).parent().children().attr("hoverIntent_t"));
		});
		$(this).css('background-position', '0px -40px');
		$('ul#navigation > li > a').animate({backgroundPosition: '0px -40px'}, 'fast');
		$('ul#navigation > li > a').find('span').animate({backgroundPosition: '0px -40px'}, 'fast');
		$('ul#navigation > li.current_cat > a').css({color: '#5c6f7c'});
		$(this).find('span').css('background-position', '0px -40px');
		$(this).animate({backgroundPosition: '0px 0px'}, 'fast');
		$(this).find('span').animate({backgroundPosition: '0px 0px'}, 'fast');
		$('#navigation li ul').animate({marginTop: '-50px'}, 'fast');
		$(this).parent().find('ul').animate({marginTop: '-12px'}, 'fast');
		current_cat_on = true;
		
	} else {
		$('ul#navigation > li > a').siblings().each(function () {
		  clearTimeout($(this).parent().children().attr("hoverIntent_t"));
		});
	
		$(this).css('background-position', '0px -40px');
		$('ul#navigation > li > a').animate({backgroundPosition: '0px -40px'}, 'fast');
		$('ul#navigation > li > a').find('span').animate({backgroundPosition: '0px -40px'}, 'fast');
		$('ul#navigation > li.current_loc > a').css({color: '#ffffff'});
		$('ul#navigation > li.current_cat > a').css({color: '#ffffff'});
		$(this).find('span').css('background-position', '0px -40px');
		$(this).animate({backgroundPosition: '0px 0px'}, 'fast');
		$(this).find('span').animate({backgroundPosition: '0px 0px'}, 'fast');
		$('#navigation li ul').animate({marginTop: '-50px'}, 'fast');
		$(this).parent().find('ul').animate({marginTop: '-12px'}, 'fast');
		current_loc_on = false;
		current_cat_on = false;
	};
};

function doNothing() {
};

function navOff() {
	if((current_loc_on==false) && (current_cat_on==false)) {
		$('ul#navigation > li:not(.current_cat) > a').animate({backgroundPosition: '0px -40px'}, 'fast');
		$('ul#navigation > li:not(.current_cat) > a').find('span').animate({backgroundPosition: '0px -40px'}, 'fast');
		$('#navigation > li > ul').animate({marginTop: '-50px'}, 'fast');
		$('#navigation > li.current_loc > ul').animate({marginTop: '-12px'}, 'fast');
		$('#navigation > li.current_cat > ul').animate({marginTop: '-12px'}, 'fast');
		$('#navigation > li.current_loc > a').animate({backgroundPosition: '0px 0px', color: '#5c6f7c'}, 'fast');
		$('#navigation > li.current_cat > a').animate({backgroundPosition: '0px 0px', color: '#5c6f7c'}, 'fast');
		$('#navigation > li.current_loc > a').css({color: '#5c6f7c'});
		$('#navigation > li.current_cat > a').css({color: '#5c6f7c'});
		$('#navigation > li.current_loc > a').find('span').animate({backgroundPosition: '0px 0px'}, 'fast');
		$('#navigation > li.current_cat > a').find('span').animate({backgroundPosition: '0px 0px'}, 'fast');
		current_loc_on = true;
		current_cat_on = true;
	};
};

function navCancel() {
	$('ul#navigation > li > a').siblings().each(function () {
      clearTimeout($(this).parent().children().attr("hoverIntent_t"));
	});

};

$ (function nav() {
		$ ('ul#navigation > li > a') .hoverIntent({
        over: navHighlight, 
        timeout: 0, 
        out: doNothing
    });
});

$ (function subNav() {
		$ ('ul#navigation > li > ul') .hoverIntent({
        over: navCancel, 
        timeout: 0, 
        out: doNothing
    });
});

$ (function subNav() {
		$ ('ul#navigation') .hoverIntent({
        over: doNothing, 
        timeout: 1200, 
        out: navOff
    });
});


$(window).scroll(function() {
  if (screen.width >= 1026) {
	var distScrolled = $(window).scrollTop();
	if (distScrolled >= 200) {
		$('#navigation_wrapper').css({'position':'fixed','top': '0', 'zIndex': '1000' }) ;
	} else {
		$('#navigation_wrapper').css({'position':'absolute','top': '200px', 'zIndex': '-1' }) ;
	};
  }
});






function hoverBox1() {
			$ ('#box1') .animate ({width: "230px", opacity: 1.0}, 500) ;
			$ ('#box1 p') .animate ({opacity: 1.0}, 500) ;
			$ ('#box2, #box3, #box4, #box5, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 500) ;
			$ ('#box2 p, #box3 p, #box4 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 500) ;
};

function hoverBox2() {
			$ ('#box2') .animate ({width: "230px", opacity: 1.0}, 500) ;
			$ ('#box2 p') .animate ({opacity: 1.0}, 500) ;
			$ ('#box1, #box3, #box4, #box5, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 500) ;
			$ ('#box1 p, #box3 p, #box4 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 500) ;
};

function hoverBox3() {
			$ ('#box3') .animate ({width: "230px", opacity: 1.0}, 500) ;
			$ ('#box3 p') .animate ({opacity: 1.0}, 500) ;
			$ ('#box1, #box2, #box4, #box5, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 500) ;
			$ ('#box1 p, #box2 p, #box4 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 500) ;
};

function hoverBox4() {
			$ ('#box4') .animate ({width: "230px", opacity: 1.0}, 500) ;
			$ ('#box4 p') .animate ({opacity: 1.0}, 500) ;
			$ ('#box1, #box2, #box3, #box5, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 500) ;
			$ ('#box1 p, #box2 p, #box3 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 500) ;
};

function hoverBox5() {
			$ ('#box5') .animate ({width: "230px", opacity: 1.0}, 500) ;
			$ ('#box5 p') .animate ({opacity: 1.0}, 500) ;
			$ ('#box1, #box2, #box3, #box4, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 500) ;
			$ ('#box1 p, #box2 p, #box3 p, #box4 p, #box6 p, #box7 p') .animate ({opacity: 0}, 500) ;
};

function hoverBox6() {
			$ ('#box6') .animate ({width: "230px", opacity: 1.0}, 500) ;
			$ ('#box6 p') .animate ({opacity: 1.0}, 500) ;
			$ ('#box1, #box2, #box3, #box4, #box5, #box7') .animate ({width: "55px", opacity: 0.2}, 500) ;
			$ ('#box1 p, #box2 p, #box3 p, #box4 p, #box5 p, #box7 p') .animate ({opacity: 0}, 500) ;
};

function hoverBox7() {
			$ ('#box7') .animate ({width: "230px", opacity: 1.0}, 500) ;
			$ ('#box7 p') .animate ({opacity: 1.0}, 500) ;
			$ ('#box1, #box2, #box3, #box4, #box5, #box6') .animate ({width: "55px", opacity: 0.2}, 500) ;
			$ ('#box1 p, #box2 p, #box3 p, #box4 p, #box5 p, #box6 p') .animate ({opacity: 0}, 500) ;
};

function hoverReset() {
			$ ('#box1, #box2, #box3, #box4, #box5, #box6, #box7') .animate ({width: "80px", opacity: 0.2}, 500) ;
			$ ('#box1 p, #box2 p, #box3 p, #box4 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 500) ;
};

function rotateBox1() {
			$ ('#box1') .animate ({width: "230px", opacity: 1.0}, 1000) ;
			$ ('#box1 p') .animate ({opacity: 1.0}, 1000) ;
			$ ('#box2, #box3, #box4, #box5, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 1000) ;
			$ ('#box2 p, #box3 p, #box4 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 1000) ;
};

function rotateBox2() {
			$ ('#box2') .animate ({width: "230px", opacity: 1.0}, 1000) ;
			$ ('#box2 p') .animate ({opacity: 1.0}, 1000) ;
			$ ('#box1, #box3, #box4, #box5, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 1000) ;
			$ ('#box1 p, #box3 p, #box4 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 1000) ;
};

function rotateBox3() {
			$ ('#box3') .animate ({width: "230px", opacity: 1.0}, 1000) ;
			$ ('#box3 p') .animate ({opacity: 1.0}, 1000) ;
			$ ('#box1, #box2, #box4, #box5, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 1000) ;
			$ ('#box1 p, #box2 p, #box4 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 1000) ;
};

function rotateBox4() {
			$ ('#box4') .animate ({width: "230px", opacity: 1.0}, 1000) ;
			$ ('#box4 p') .animate ({opacity: 1.0}, 1000) ;
			$ ('#box1, #box2, #box3, #box5, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 1000) ;
			$ ('#box1 p, #box2 p, #box3 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 1000) ;
};

function rotateBox5() {
			$ ('#box5') .animate ({width: "230px", opacity: 1.0}, 1000) ;
			$ ('#box5 p') .animate ({opacity: 1.0}, 1000) ;
			$ ('#box1, #box2, #box3, #box4, #box6, #box7') .animate ({width: "55px", opacity: 0.2}, 1000) ;
			$ ('#box1 p, #box2 p, #box3 p, #box4 p, #box6 p, #box7 p') .animate ({opacity: 0}, 1000) ;
};

function rotateBox6() {
			$ ('#box6') .animate ({width: "230px", opacity: 1.0}, 1000) ;
			$ ('#box6 p') .animate ({opacity: 1.0}, 1000) ;
			$ ('#box1, #box2, #box3, #box4, #box5, #box7') .animate ({width: "55px", opacity: 0.2}, 1000) ;
			$ ('#box1 p, #box2 p, #box3 p, #box4 p, #box5 p, #box7 p') .animate ({opacity: 0}, 1000) ;
};

function rotateBox7() {
			$ ('#box7') .animate ({width: "230px", opacity: 1.0}, 1000) ;
			$ ('#box7 p') .animate ({opacity: 1.0}, 1000) ;
			$ ('#box1, #box2, #box3, #box4, #box5, #box6') .animate ({width: "55px", opacity: 0.2}, 1000) ;
			$ ('#box1 p, #box2 p, #box3 p, #box4 p, #box5 p, #box6 p') .animate ({opacity: 0}, 1000) ;
};

function rotateReset() {
			$ ('#box1, #box2, #box3, #box4, #box5, #box6, #box7') .animate ({width: "80px", opacity: 0.2}, 1000) ;
			$ ('#box1 p, #box2 p, #box3 p, #box4 p, #box5 p, #box6 p, #box7 p') .animate ({opacity: 0}, 1000) ;
};






$ (function() {
		$ ('#box1') .hoverIntent({
        over: hoverBox1, 
        timeout: 0, 
        out: doNothing
    });
});

$ (function() {
		$ ('#box2') .hoverIntent({
        over: hoverBox2, 
        timeout: 0, 
        out: doNothing
    });
});

$ (function() {
		$ ('#box3') .hoverIntent({
        over: hoverBox3, 
        timeout: 0, 
        out: doNothing
    });
});

$ (function() {
		$ ('#box4') .hoverIntent({
        over: hoverBox4, 
        timeout: 0, 
        out: doNothing
    });
});

$ (function() {
		$ ('#box5') .hoverIntent({
        over: hoverBox5, 
        timeout: 0, 
        out: doNothing
    });
});

$ (function() {
		$ ('#box6') .hoverIntent({
        over: hoverBox6, 
        timeout: 0, 
        out: doNothing
    });
});

$ (function() {
		$ ('#box7') .hoverIntent({
        over: hoverBox7, 
        timeout: 0, 
        out: doNothing
    });
});




// Billboard Functions
$(function() {
  var timer = setInterval(rotate, 10000);
  var counter = 1;
 
  
  function rotateRandom() {
  	  var randomNumber=Math.floor(Math.random() * 7) + 1;
	  if (randomNumber==1){ 
      	rotateBox1();
      }
	  else if(randomNumber==2){  
      	rotateBox2();
      }
	  else if(randomNumber==3){  
      	rotateBox3();
      }
	  else if(randomNumber==4){  
      	rotateBox4();
      }
	  else if(randomNumber==5){  
      	rotateBox5();
      }
	  else if(randomNumber==6){  
      	rotateBox6();
      }
	  else {  
      	rotateBox7();
      }
  };
  
  
  function rotate() {
    if(counter==1){ 
      counter=2;
      rotateRandom();
	}
	else { 
      counter=1;
      rotateReset();
    }
  };

  $ (function() {
    $ ('#header_image_inner') .hover(
      function() {
        clearInterval(timer);
      },
      function() {
      	hoverReset();
        counter=1;
        timer = setInterval(rotate, 10000);
      }
    );
  });
  
});


