$(document).ready(function(){

/* header panel actions 

$('li.advanced').mouseenter(function() {
 $('.panel.new').slideDown("fast");
});

$('.panel.new').mouseleave(function() {
 $('.panel.new').slideUp("fast");
});

$('body').click(function() {
 $('.panel.new').slideUp("fast");
});

$('.panel.new').click(function(event){
     event.stopPropagation();
 });*/

$(".textarea p a#findout").click(function() {
 $(".textarea .bullets").slideDown("fast");
});

	
	// Expand Panel
	$("#open").click(function(){
		$(".panel").slideDown("fast");	
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$(".panel").slideUp("fast");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#options a").click(function () {
		$("#options a").toggle();
	});	
	
	$(".triggermenu").click(function(){
		$(".rt_menu").slideDown("fast");	
	});	
	$(".triggermenuclose").click(function(){
		$(".rt_menu").slideUp("fast");	
	});
	
	$("a.usrs").click(function () {
		$("a.usrs").toggle();
	});	
	
	$(".triggeropen").click(function(){
		$(".login").slideDown("fast");	
	});	
	$(".triggerclose").click(function(){
		$(".login").slideUp("fast");	
	});
	
	$(".userbox a.opt.fst").click(function () {
		$(".userbox a.opt.fst").toggle();
	});
	
	$(".trigger2open").click(function(){
		$(".register").slideDown("fast");	
	});	
	$(".trigger2close").click(function(){
		$(".register").slideUp("fast");	
	});		
	$(".userbox a.opt.snd").click(function () {
		$(".userbox a.opt.snd").toggle();
	});
	
	// Expand Panel
	$("#open2").click(function(){$(".expander").slideDown("fast");});	
	$("#close2").click(function(){$(".expander").slideUp("fast");});		
	$("a.trigger2").click(function(){$("a.trigger2").toggle();});		
	
	$("#advert li.images ol li").hover(function() {
												
 	$("#advert li.images ol li a").click(function() {
		
		var mainImage = $(this).attr("href"); //Find Image Name
		$("#main_view img").attr({ src: mainImage });
		return false;		
	});
	
	});
	
	//footer sticky message bar
	//Adjust panel height

	$.fn.adjustPanel = function(){ 

		$(this).find("ul, .subpanel").css({ 'height' : 'auto'}); //Reset subpanel and ul height

		

		var windowHeight = $(window).height(); //Get the height of the browser viewport

		var panelsub = $(this).find(".subpanel").height(); //Get the height of subpanel	

		var panelAdjust = windowHeight - 100; //Viewport height - 100px (Sets max height of subpanel)

		var ulAdjust =  panelAdjust - 25; //Calculate ul size after adjusting sub-panel (27px is the height of the base panel)

		

		if ( panelsub >= panelAdjust ) {	 //If subpanel is taller than max height...

			$(this).find(".subpanel").css({ 'height' : panelAdjust }); //Adjust subpanel to max height

			$(this).find("ul").css({ 'height' : ulAdjust}); //Adjust subpanel ul to new size

		}

		else if ( panelsub < panelAdjust ) { //If subpanel is smaller than max height...

			$(this).find("ul").css({ 'height' : 'auto'}); //Set subpanel ul to auto (default size)

		}

	};
//Execute function on load

	$("#chatpanel").adjustPanel(); //Run the adjustPanel function on #chatpanel

	//Each time the viewport is adjusted/resized, execute the function

	$(window).resize(function () { 

		$("#chatpanel").adjustPanel();

	});

	

	//Click event on Chat Panel + Alert Panel	

	$("#chatpanel a:first").click(function() { //If clicked on the first link of #chatpanel and #alertpanel...

		if($(this).next(".subpanel").is(':visible')){ //If subpanel is already active...

			$(this).next(".subpanel").hide(); //Hide active subpanel

			$("#footpanel li a").removeClass('active'); //Remove active class on the subpanel trigger

		}

		else { //if subpanel is not active...

			$(".subpanel").hide(); //Hide all subpanels

			$(this).next(".subpanel").toggle(); //Toggle the subpanel to make active

			$("#footpanel li a").removeClass('active'); //Remove active class on all subpanel trigger

			$(this).toggleClass('active'); //Toggle the active class on the subpanel trigger

		}

		return false; //Prevent browser jump to link anchor

	});

	

	//Click event outside of subpanel

	$(document).click(function() { //Click anywhere and...

		$(".subpanel").hide(); //hide subpanel

		$("#footpanel li a").removeClass('active'); //remove active class on subpanel trigger

	});

	$('.subpanel ul').click(function(e) { 

		e.stopPropagation(); //Prevents the subpanel ul from closing on click

	});

	

	//Delete icons on Alert Panel

	$("#alertpanel li").hover(function() {

		$(this).find("a.delete").css({'visibility': 'visible'}); //Show delete icon on hover

	},function() {

		$(this).find("a.delete").css({'visibility': 'hidden'}); //Hide delete icon on hover out

	});


	
});

$(function() {
    // make the cursor over <li> element to be a pointer instead of default
	$('#adlist li.linked').css('cursor', 'pointer')
    // iterate through all <li> elements with CSS class = "clickable"
    // and bind onclick event to each of them
    .click(function() {
        // when user clicks this <li> element, redirect it to the page
        // to where the fist child <a> element points
        window.location = $('a', this).attr('href');
    });
	
	$('#list li, ul.display li.rw, #blist li, #list.main li, .message-list li.active').css('cursor', 'pointer')
	.click(function() {
        window.location = $('a', this).attr('href');
    });

});
