//gtPage = location.hash;
//if(gtPage) {
//	ldPage = gtPage.substring(1);
//	window.location = ldPage;
//}



$(document).ready(function(){
			
				$(".block").each(function(){					
				$("#home_btn").corner("round bottom").hide();
				$("#content").corner("round top");
				$("#loginnav").corner("round bottom");
				$("#topnav").corner("round bottom");
				$("#left_bar").corner("round tl");
				$("#right_bar").corner("round tr");
				$("#bottom_content").corner("bottom round");
				});	
				$(".scrollable_djl").scrollable();
				
				flowActive(); 
				
				//Chat Functions
				$("#btn_chat").click(function() {
					$("#chat_div").toggle("slow");
					return false;
				});
				$("#btn_chat_handle").dblclick( function() {
							$("#chat_div").toggleClass("chat_div_min");
				});
				
				$("#btn_chat_handle").mouseup(function(){
				      $("#chat_div").draggable({disabled: true });
			    }).mousedown(function(){
			    	$("#chat_div").draggable({disabled: false });
			    });
				
				$("div#btn_chat_close").click( function() {
					$("#chat_div").hide("slow");
				});	
				
			});
		
		function homeHover() {
			$("#subnav").css({"overflow":"visible"});
			$("#page").mousemove(function(e) {
			var mousex = e.pageX - this.offsetLeft - 55;
			var mousePos = mousex
			if (mousex > 860) {
				mousePos = 860;
			}
			if (mousex < 0) {
				mousePos = 0;
			}
	        $("#home_btn").css({"left": mousePos });
		    });
			$("#subnav").hover(function(){
				$("#home_btn").fadeIn("slow");
			}, function(){
				$("#home_btn").fadeOut("slow");
			});
			$("#home_btn").click(function() {
				$("#viewer_blocker").show();
				$("#video_box").show();
				$("#content_overlay").slideUp("slow").empty();
				$("#subnav").animate({top: "402px"}).css({"overflow":"hidden"}).uncorner();
				location.hash = '';
				return false;
			});
		}
		
		function homeHovera() {
			$("#subnav").css({"overflow":"visible"});
			$("#page").mousemove(function(e) {
			var mousex = e.pageX - this.offsetLeft - 55;
	        $("#home_btn").css({"left": mousex });
		    });
			
			$("#subnav").hover(function(){
				$("#home_btn").fadeIn("slow");
			}, function(){
				$("#home_btn").fadeOut("slow");
			});
			
		}
		
		function subNavTop() {
			$("#subnav").css({"border-bottom": "solid 2px #E7DDA2"}).corner("round top");
			$("#subnav").animate({
				top: "0px"
			}, function(){
				homeHover();
				$("#viewer_blocker").hide();
				$("#top_content").css({"top": "50px"}).corner("round bottom");
				$("#content_overlay").css({"height":"705px" }).slideDown("fast");
			});

		}
		
		function subNavTop2() {
			$("#subnav").css({"border-bottom": "solid 2px #E7DDA2"}).corner("round top");
			$("#subnav").animate({
				top: "0px"
			}, function(){
				homeHover();
				$("#top_content").css({"top": "172px"}).corner("round bottom");
				$("#content_overlay").css({"height":"650px" }).slideDown("fast");
				$("#viewer_blocker").hide();
			});

		}
		
		function flowActive() {
			$.getScript("http://jlis.sceedle.com/js/flowplayer-3.2.2.min.js", function(){
				
				$(function() {

					// setup overlay actions to buttons
					$("a.player_btn[rel]").overlay({

						onLoad: function(content) {
						$("#subnav").css("z-index","2");
							// find the player contained inside this overlay and load it
							this.getOverlay().find("a.player").flowplayer(0).load();
						},
						
						onClose: function(content) {
							$("#subnav").css("z-index","4");
							$f().unload();
						}
						
					});				
					
					// install flowplayers
					$("a.player").flowplayer("http://jlis.sceedle.com/media/flash/flowplayer/flowplayer-3.2.2.swf"); 
				});	
			});
		}
		
		//dj team button
		$("#btn_djlist").click(function() {
			$("#content_overlay").load("dj_list/a_index #a_content", function(){
				location.hash = 'dj_list';
				subNavTop();
				$(".scrollable_djl").scrollable();
					$("a.dj_link").click(function() {
					
					var djLink = "dj_list/a_dj_info/" + $(this).attr("rel");location
					var djName = $(this).attr("href");
					location.hash = djName;
					
					$("#top_content").load(djLink + " #top_content", function(){
							flowActive();
							$(".player, .player_btn").click(function(){
								$("#video_box").hide();
								
							});
					});
					
					return false;
				});
			});
			return false;
		});	
		

		//left bar dj info
		
		function currentDjRefresh() {
			var timeNow =  new Date();
			var minutes = timeNow.getMinutes();
			var seconds = timeNow.getSeconds();
			var refreshTime = (60*60*1000) - (minutes * 60 * 1000) - (seconds * 1000) + 10000;
			
			$("#left_bar").oneTime(refreshTime, "djr1",function() {
  				  $(this).load("home/show_current_dja");
  				  currentDjRefresh();
				});
		}
		currentDjRefresh();

		
		$("#btn_login").click(function() {
  			$("#my_account").load("my_account/login").show("slow").corner("round");
  			return false;
		});
		$("#btn_sign_up").click(function() {
  			$("#my_account").load("my_account/sign_up").show("slow").corner("round");
  			return false;
		});		
		
		//Mix of the week button
		$("#btn_motw").click(function() {
			$("#left_bar").stopTime("djr1");
  			$("#left_bar").load("home/show_motw_dj");
  			$("#main_content").load("home/show_motw");
			$(this).hide();
			$("#btn_live").show();
			return false;
		});		
		
		//live feed button
		$("#btn_live").click(function() {
			//currentDjRefresh();
  			$("#left_bar").load("home/show_current_dja");
  			$("#main_content").load("home/show_live_feed");
  			$(this).hide();
			$("#btn_motw").show();
			return false;
		});	
		
		//schedule button
		$("#btn_sched").click(function() {
			$("#content_overlay").load("schedule/a_index #a_content", function(){
				location.hash = 'schedule';
				subNavTop();
				$("a.dj_link").click(function() {
					var djLink = "dj_list/a_dj_info/" + $(this).attr("rel");
					$("#top_content").load(djLink + " #top_content", function(){
						$("a#player").click(function(){
							var trackUrl = $(this).attr("href");
							$.getScript("js/flowplayer.min.js", function(){
								
								$(function() {

									// setup overlay actions to buttons
									$("a[rel]").overlay({

										// use the Apple effect for overlay
										effect: 'apple',		
										
										expose: '#789',				
										
										onLoad: function(content) {
											// find the player contained inside this overlay and load it
											this.getOverlay().find("a.player").flowplayer(0).load();
										},
										
										onClose: function(content) {
											$f().unload();
										}
									});				
									
									// install flowplayers
									$("a.player").flowplayer("media/flash/flowplayer.swf"); 
								});
								
								
							});
							return false;
						});
					});
					return false;
				});

				$.getScript("js/jquery.mousewheel.js");
      
					        $('#timeline').mousedown(function (event) {
					            $(this)
					                .data('down', true)
					                .data('x', event.clientX)
					                .data('scrollLeft', this.scrollLeft);
					                
					            return false;
					        }).mouseup(function (event) {
					            $(this).data('down', false);
					        }).mousemove(function (event) {
					            if ($(this).data('down') == true) {
					                this.scrollLeft = $(this).data('scrollLeft') + $(this).data('x') - event.clientX;
					            }
					        }).mousewheel(function (event, delta) {
					            this.scrollLeft -= (delta * 30);
					        }).css({
					            'overflow' : 'hidden',
					            'cursor' : '-moz-grab'
					        });
					    
					    $(window).mouseout(function (event) {
					        if ($('#timeline').data('down')) {
					            try {
					                if (event.originalTarget.nodeName == 'BODY' || event.originalTarget.nodeName == 'HTML') {
					                    $('#timeline').data('down', false);
					                }                
					            } catch (e) {}
					        }
					    });
			});
			return false;
		});	

	//members button

	$("#btn_members").click(function() {
		$("#content_overlay").load("my_account/login #account_main", function(){
			subNavTop2();	
		});
		return false;
	});
	//login button

	$("#btn_login").click(function() {
		$("#content_overlay").load("my_account/login #account_main", function(){
			subNavTop2();	
		});
		return false;
	});
	//sign up button

	$("#btn_sign_up").click(function() {
		$("#content_overlay").load("my_account/sign_up #account_main", function(){
			subNavTop2();	
		});
		return false;
	});

	
	
	//store button
	$("#btn_store").click(function() {
		$("#content_overlay").load("store/a_index #a_content", function(){
			location.hash = 'store';
			subNavTop();
		});
		return false;
	});	
		
		
		
		//dj link
		$("#bottom_content a.dj_link").click(function() {
			var djLink = "dj_list/a_dj_info/" + $(this).attr("rel");
			var djName = $(this).attr("href");
			$("#content_overlay").load(djLink + " #top_content", function(){
				subNavTop2();
				
				flowActive();					
				location.hash = djName;
				$(".player, .player_btn").click(function(){
					$("#video_box").hide();
					
				});
				
			});
			return false;
		});
		
		//current dj link
		$("#current_dj  a").click(function() {
			var djLink = "dj_list/a_dj_info/" + $(this).attr("rel");
			var djName = $(this).attr("href");
			$("#content_overlay").load(djLink + " #top_content", function(){
				subNavTop2();
				
				flowActive();					
				location.hash = djName;
				$(".player, .player_btn").click(function(){
					$("#video_box").hide();
					
				});
				
			});
			return false;
		});
	
		

