//<[CDATA[

var ragoAlert;

function setCookie(name, num){
    $.cookie(name, num);
    window.location.reload();
}

function getCookie(name){
    return $.cookie(name);
}

/* gallery functions */

function loadPage(page){
	$('#gallery').load('/gallery/gallery.php?gallery='+gallery, function(){
		loadGallery();
	});	
}
		
function loadGallery(){
    $("#gallery").galleria({
        transition: 'fade',
        autoplay: 3000,
        showInfo: false,
        showCounter: false,
        width: 650,
        height: 350
    });
}

$(document).ready(function() {

	if(ragoAlert!=''){
		//alert(ragoAlert);
		$('#alert').append(ragoAlert);
		$('#alertContainer').slideDown('slow');
		// hides the signup by tool stripe
		$('#alertClose').click(function() {
			$('#alertContainer').slideUp('slow');
		});
	}

	$("img.rollover").hover(
	function(){
		this.src = this.src.replace("_off","_on");
	}, function() {
		this.src = this.src.replace("_on","_off");
		}
	);
		
	/* new search */

	$("#formAdditional").css("display", "none");

	$("#searchBar").focus(function() {
		var searchVal = $(this).val();
		if (searchVal=="> Search Auctions"){
			$(this).val("");
		}
	});
	
	var searchTimeout;
	
	$("#topSearch").mouseenter(function(){
		if(searchTimeout){
			window.clearTimeout(searchTimeout);
		}
      	$("#formAdditional").slideDown();
		//$("#topSearch").css({background:"#eaeaea"});
		$("#btnSubmit").fadeIn(200);
    }).mouseleave(function(){
    	searchTimeout = window.setTimeout(fadeInput, 200, true);
    });
	
	$("#searchBar").blur(function() {
		var searchVal = $(this).val();
		if (searchVal==""){
			$(this).val("> Search Auctions");
		}
	});


	function fadeInput() {
		$("#formAdditional").slideUp(200, function(){
			//$("#topSearch").fadeOut("slow").css("background-color", "#FFF");
			$("#btnSubmit").fadeOut();
			$("#topSearch").animate({"backgroundColor" : "#fff"});
		});
	}
	
	/* end new search */


		//$("ul.sf-menu").superfish(); 
		
		// hides the signup as soon as the DOM is ready
		$('#signup').css('display','block');
		$('#signup').hide();
		
		// shows the signup by site tool
		$('a.signupToggle').click(function() {
			if ($.browser.msie) {
				window.location = "/signup";
			} else {
				$('#signup').slideToggle(500);
				$("body").ScrollToAnchors('top');
			}
		  return false;
		});
		
		// shows the signup by tool stripe
		$('a#alertTool').click(function() {
			if ($.browser.msie) {
				window.location = "/signup/";
			} else {
				$('#signup').slideToggle(500);
				$("body").ScrollToAnchors('top');
			}
		});
		
		$('a#signupCancel').click(function() {
		  $('#signup').slideToggle(400);
		  return false;
		});
		
		$(".nav").children("li").each(function() {
			var current = "nav current-" + ($(this).attr("class"));
			var parentClass = $(".nav").attr("class");
			if (parentClass != current) {
				$(this).children("a").css({backgroundImage:"none"});
			}
		});	

		function attachNavEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="nav-' + myClass + '"></div>');
				$("div.nav-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.nav-" + myClass).fadeOut(200, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.nav-" + myClass).attr("class", "nav-" + myClass + "-click");
			}).mouseup(function() {
				$("div.nav-" + myClass + "-click").attr("class", "nav-" + myClass);
			});
		}
		
		// create events for each nav item
		attachNavEvents(".nav", "deptMenu00");
		attachNavEvents(".nav", "deptMenu01");
		attachNavEvents(".nav", "deptMenu02");
		attachNavEvents(".nav", "deptMenu03");
		attachNavEvents(".nav", "deptMenu04");
		attachNavEvents(".nav", "deptMenu05");
		attachNavEvents(".nav", "deptMenu06");
	
		function attachToolEvents(parent, myClass) {
			$(parent + " ." + myClass).mouseover(function() {
				$(this).append('<div class="tools-' + myClass + '"></div>');
				$("div.tools-" + myClass).css({display:"none"}).fadeIn(200);
			}).mouseout(function() {
				$("div.tools-" + myClass).fadeOut(200, function() {
					$(this).remove();
				});
			}).mousedown(function() {
				$("div.tools-" + myClass).attr("class", "tools-" + myClass + "-click");
			}).mouseup(function() {
				$("div.tools-" + myClass + "-click").attr("class", "tools-" + myClass);
			});
		}

		// create events for each nav item
		attachToolEvents(".tools", "auctionTool00");
		attachToolEvents(".tools", "auctionTool01");
		attachToolEvents(".tools", "auctionTool02");
		attachToolEvents(".tools", "auctionTool03");
		attachToolEvents(".tools", "auctionTool04");
	
		// Toggle Font Size
		$(".toggleFont").click(function(){
			var currentFontSize = $('.bodytext').css('font-size');
			
			if (currentFontSize == '11px'){
				$('#page').css('font-size', '12px');
			} else {
				$('#page').css('font-size', '11px');
			} 
			
		  return false;
		});

		$(function () {
		    // find the div.fade elements and hook the hover event
		    $('div.fade').hover(function() {
		        // on hovering over find the element we want to fade *up*
		        var fade = $('> div', this);
		
		        // if the element is currently being animated (to fadeOut)...
		        if (fade.is(':animated')) {
		            // ...stop the current animation, and fade it to 1 from current position
		            fade.stop().fadeTo(200, 1);
		            //fade.fadeIn(100);
		        } else {
		            fade.fadeIn(200);
		        }
		    }, function () {
		    
		        var fade = $('> div', this);
		        if (fade.is(':animated')) {
		            fade.stop().fadeTo(400, 0, function(){
		                fade.removeAttr('style');
		            });
		        } else {
		            fade.fadeOut(400);
		        }
		    });
		});

		loadHeads();

		/* gallery events */
		
	    //$('body').append('<div id="sscontainer"><div id="gallery"></div></div>');
	    
	    $('.galleryClick').click(function() {
		    $('body').append('<div id="sscontainer"><div id="gallery"></div></div>', function(){});
	    	gallery = $(this).attr('id');
			$("#sscontainer").lightbox_me({
				overlayCSS: {
					background: '#222222', 
					opacity: .9
					},
				centered: true,
				onLoad: function() {
	            	loadPage(gallery);
	            },
	            onClose: function(){
	            	//$('#gallery').html('');
	            	//$('body').append('<div id="sscontainer"><div id="gallery"></div></div>');
	            },
	            destroyOnClose: true
	        });       
	        return false;
	    });

		$(function() {
	    $('img[data-hover]').hover(function() {
	        $(this).attr('tmp', $(this).attr('src')).attr('src', $(this).attr('data-hover')).attr('data-hover', $(this).attr('tmp')).removeAttr('tmp');
	    }).each(function() {
	        $('<img />').attr('src', $(this).attr('data-hover'));
	    });
	});

	$('#magPromoLink').click(function(){
		$('#magPromoContent').slideToggle();
	})

}); // end document ready function

var win = null;

function NewWindow(mypage,myname,w,h,scroll,pos){
	if (pos=="random") {
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if (pos=="center"){
		LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;
	} else if((pos!="center" && pos!="random") || pos===null){
		LeftPosition=0;
		TopPosition=20;
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}

//]]>
