var isMobile = false;
var backgroundSlide = {};
var opened = false;
var menu_width;
var color_txt = '#CED0D1';
var color_txt_over = '#4B333F';
var box_back = '#4B333F';
var box_back_over = '#ffffff';

	
$(document).ready(function(){
	if( navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPod/i) || navigator.userAgent.match(/iPad/i)){
	 isMobile = true;
	};
		
	
	menu_width = $('#menu').width();
	menu_height = $('#menu').height();
	drop_down_width = $('#drop_down_btn').width();
	
	var currentItem = "";
	var drop_down_btn = $('#drop_down_btn');
	
	//CHECK TO SEE IF IT"S MOBILE
	if(isMobile == false){
		//DROP DOWN HOVER
		drop_down_btn.hover( function () {
			$(this).css('cursor','pointer');
			if(opened == false){
				$(this).animate({backgroundColor: box_back_over,color: color_txt_over},250, 'easeOutExpo');
				$('#arrow').rotate({angle:0,animateTo:90},250, 'easeOutExpo');
				$('#arrow').animate({color: color_txt_over},250, 'easeOutExpo');
				//$('#arrow').css('margin-top', '3px')
			};
									
		}, function () {
			if(opened == false){
				$(this).css('cursor','auto');
				$(this).animate({backgroundColor: box_back, color:color_txt},250, 'easeOutExpo');
				$("#arrow").rotate({ angle:90,animateTo:0},250, 'easeOutExpo');
				$("#arrow").animate({color: color_txt},250, 'easeOutExpo');
				//$('#arrow').css('margin-top', '1px')
			};
		});
		
		//LI HOVER EFFECT
		$("li", "#menu").hover( function () {
			//$(this).css('background-color', '#ff0000')
			//alert($(this).html())
			if($(this).attr("class") != "break"){
				$(this).stop().animate({backgroundColor:box_back},350, 'easeOutExpo');
				
				$("a", this).stop().animate({color:color_txt},350, 'easeOutExpo');
				$(this).css('cursor','pointer');
			}
									
		}, function () {
			if($(this).attr("class") != "break"){
				
				$(this).stop().animate({backgroundColor:box_back_over},150, 'easeOutExpo');
				$("a", this).stop().animate({color:color_txt_over},150, 'easeOutExpo');
				$(this).css('cursor','auto');
			}
		});	
	};
	//DROP DOWN CLICK
	drop_down_btn.click( function(e) { 
		if(opened == false){
			opened = true
			drop_down_width = $('#drop_down_btn').width();
			if($(this).width() < menu_width){
				$('#menu').css('width', drop_down_width);
				$("#menu").animate({height:'toggle', width:menu_width}, 500, 'easeOutExpo');
				$(this).animate({width:menu_width-20, backgroundColor: box_back_over,color: color_txt_over}, 500, 'easeOutExpo');
				$('#arrow').rotate({angle:0,animateTo:90},250, 'easeOutExpo');
				$('#arrow').animate({color: color_txt_over},250, 'easeOutExpo');
			}else{
				$('#menu').css('width', drop_down_width);
				$("#menu").animate({height:'toggle', width:$(this).width()+20, backgroundColor: box_back_over,color: color_txt_over}, 500, 'easeOutExpo');
				$('#arrow').rotate({angle:0,animateTo:90},250, 'easeOutExpo');
				$('#arrow').animate({color: color_txt_over},250, 'easeOutExpo');
				//$(this).animate({width:menu_width-20}, 500, 'easeOutExpo');
			}
		
				
				
		}else{
			opened = false
			
			$('#drop_down_btn').animate({backgroundColor: box_back, color:color_txt, width:$('#txt').width()+30},500, 'easeOutExpo');
			$("#menu").animate({height:'toggle', width:$('#txt').width()+48},500, 'easeOutExpo');
			$("#arrow").rotate({ angle:90,animateTo:0},500, 'easeOutExpo');
			$("#arrow").animate({color: color_txt},500, 'easeOutExpo');
			
		
			
		};
		
	});
	//MENU CLICK
	$("li", "#menu").click(function(event) {
		if($(this).attr("class") != "break"){
			event.preventDefault();
			opened = false
			var new_txt = $(this).text();
			$("#menu").animate({height:'toggle'},500, 'easeOutExpo');
			
			$('#drop_down_btn').animate({backgroundColor: box_back, color:color_txt},500, 'easeOutExpo');
			$("#arrow").rotate({ angle:90,animateTo:0},500, 'easeOutExpo');
			$("#arrow").animate({color: color_txt},500, 'easeOutExpo');
			
			$('#txt').animate({width:'toggle'},500,'easeOutExpo',function(){
				$('#txt').html(new_txt);
				$('#txt').animate({width:'toggle'},500,'easeOutExpo');
				$('#drop_down_btn').animate({width:$('#txt').width()+30}, 500, 'easeOutExpo');
			});
			
			var hash = $("a",this).attr('href');
			window.location = '#'+hash;	
		}
	})
					
	
	$(window).hashchange( function(){
		var hash = location.hash
		var nohash 
		
		if( hash == ""){
			hash = "#pages/index.html"
			nohash = hash.replace('#','')
			FIRE_AJAX_LOAD()
		}else{
			nohash = hash.replace('#','')
			$('#lower_left').fadeOut(3,CLEAROUT)
			$('#content').fadeOut(3,FIRE_AJAX_LOAD)
		}
		
		function CLEAROUT(){
			$('#lower_left').html("");
		}
		function FIRE_AJAX_LOAD(){
						
			var loadUrl = nohash//"pages/"+nohash+".html";
			//console.log(loadUrl)
			$.ajax({
				type: "POST", 
				url: loadUrl, 
				data: "",
				dataType: 'html', 
				success: function(html){
					$("#content").html(html);
					$('#content').fadeIn(500, 'easeOutExpo');
					$('#lower_left').fadeIn(500, 'easeOutExpo');
					$('#info_box').css('display', 'none');
					$('#video_box').css('display', 'none');
					
					//INFO BUTTON
					if($('#info_box').length != 0){
						$('#lower_left').append('<div id="info"><a href="#">INFO</a></div>');
					}else{
						
					};
					
					$("#info a").click(function(event) {
						event.preventDefault();
					});
					$("#info").click( function(e) { 
					
						$("#info_box").fadeToggle(500, 'easeOutExpo');
						if($('#video_box').is(':visible')){
							$("#video_box").fadeToggle(500, 'easeOutExpo');
							$("a",'#video').animate({backgroundColor: box_back, color:color_txt},250, 'easeOutExpo');
							
						};
						
					});
										
					//VIDEO BUTTON
					if($('#video_box').length != 0){
						$('#lower_left').append('<div id="video"><a href="#">VIDEO</a></div>');
					}else{
						
					};
					
					$("#video a").click(function(event) {
						event.preventDefault();
					})
					$("#video").click( function(e) { 
						$("#video_box").fadeToggle(500, 'easeOutExpo');
						if($('#info_box').is(':visible')){
							$("#info_box").fadeToggle(500, 'easeOutExpo');
							$("a",'#info').animate({backgroundColor: box_back, color:color_txt},250, 'easeOutExpo');
						};
					});
					
					//LINK
					if($('#link_box').length != 0){
						$('#lower_left').append('<div id="link"><a href="'+$('a', '#link_box').attr("href")+'">LINK</a></div>');
					}else{
						
					};
					
					$("#link a").click(function(event) {
						event.preventDefault();
					})
					
					
					$("#link").click( function(e) { 
						var link_url = $('a', this).attr('href');
						window.open(link_url, 'target=_blank');
						
						
					});
					
					//NOT MOBILE
					
					if(isMobile == false){
						//INFO BOX
						$("#info").hover( function () {
							
							$("a",this).animate({backgroundColor: box_back_over,color: color_txt_over},250, 'easeOutExpo');
													
						}, function () {
							if($('#info_box').is(':visible')){
							}else{
								$("a",this).animate({backgroundColor: box_back, color:color_txt},250, 'easeOutExpo');
							}
						});
						
						//VIDEO BOX
						$("#video").hover( function () {
							
							$("a",this).animate({backgroundColor: box_back_over,color: color_txt_over},250, 'easeOutExpo');
							//$('a',this).css('backgroundPosition', '25px 12px');
							//$('a',this).html("");
							//$('.moveme').css("backgroundPosition","0px 0px").animate({"backgroundPosition":"-100px 10px"});
								
											
						}, function () {
							if($('#video_box').is(':visible')){
							}else{
								$("a",this).animate({backgroundColor: box_back, color:color_txt},250, 'easeOutExpo');
							//	$('a',this).css('backgroundPosition', '25px -8px');
								
							}
						});
						
						//LINK BOX
						$("#link").hover( function () {
							
							$("a",this).animate({backgroundColor: box_back_over,color: color_txt_over},250, 'easeOutExpo');
													
						}, function () {
							
							$("a",this).animate({backgroundColor: box_back, color:color_txt},250, 'easeOutExpo');
						});
					};
				},
				error: function(){
					//alert('fail');	
				}
				
				
			 /* url: loadUrl,
			  data: "",
			  cache: false,
			  dataType: 'html',
			  success: function(html){
				  
				//console.log(html);
				$("#content").html(html);
				$('#content').fadeIn(500, 'easeOutExpo');
				$('#lower_left').fadeIn(500, 'easeOutExpo');

			  },
			  error: function(){
				alert('crap!')  
			  }*/
			});
			
			
		
			/*$("#content").html(ajax_load);
			$.get(
				loadUrl,
				function(responseText){
					var info_div = document.createElement('div'); 
					if($('#info_box')){
						info_div.innerHTML = [ '<div id="info"><a href="">INFO</a></div>']
						$('#lower_left').html(info_div);
					}else{
						info_div.innerHTML = ['']
						$('#lower_left').append(info_div);
					}
					var info_btn = $('#info');
					info_btn.click( function(e) { 
						$("#info_box").fadeToggle([3])
						//alert('pop')
					});
					
					BACKGROUND();
				},
				"html"
			);
			
			$("#content").html(ajax_load).load(loadUrl);
			$('#content').fadeIn([5])
			$('#lower_left').fadeIn([5])
			$('.pop_up').css('display','none')
			*/
			
			//needs to be fired with every ajax call
			
		}
		
		
	});
	$(window).hashchange();
				
	
	//TEST TO SE IF FLASH IS INSTALLED
	try {
		var fo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
		if(fo) hasFlash = true;
	}catch(e){
		if(navigator.mimeTypes ["application/x-shockwave-flash"] != undefined) hasFlash = true;
	}
});
