var $j = jQuery.noConflict();

$j(document).ready(function(){
	$j(".loginButton").hover(function(){
		$j(this).attr("src", fnChangeFrame($j(this).attr("src"), true));
	}, function(){
		$j(this).attr("src", fnChangeFrame($j(this).attr("src"), false));
	});
	
	$j(".loginButton").click(function(){
		$j(".loginButt").fadeOut(function(){
			$j(".loginForm").fadeIn();
		});
	});
	
	function fnChangeFrame(url, hovering){
		if(url != ""){
			oldUrl = url.substring(0, url.lastIndexOf("/"));
			newUrl = url.substring(url.lastIndexOf("/"));
			arrUrl = newUrl.split(".");
			if(hovering){
				arrUrl[0] = arrUrl[0] + "_f2";
			}else{
				arrUrl[0] = arrUrl[0].substring(0, arrUrl[0].indexOf("_f2"));
			}
			newUrl = oldUrl + arrUrl[0]+"."+arrUrl[1];
			return newUrl;
		};
	}
	
	var $urlPath = "http://www.ianfleming.com/draft/"

	$j("div.otherBondAuthors").hover(function(){
		$j(this).css("background", "transparent url("+$urlPath+"assets/images/template/otherBondAuthors_f2.gif)");
	}, function(){
		$j(this).css("background-image", "url("+$urlPath+"assets/images/template/otherBondAuthors.gif)");
	});
	
	var $items = $j("div.otherBondAuthorsBg a");
	var $cur = 0;
	var $old = 0;
	var $num = $items.size();
	var $tt = 500;
	var $et = 3000;
	
	$items.eq(0).css("left", "0px");
	
	var t = setInterval(fnCycleAuthors, $et);
	
	function fnCycleAuthors(){
		$cur = ($old+1) % $num;
		
		$items.eq($old).animate({left: "-150px"}, $tt, function(){
			$j(this).css("left", "150px");
		});
		$items.eq($cur).animate({left: "0px"}, $tt, function(){
			$old = $cur;
		});
	};
});

$j(document).ready(function(){
	$j(".checkSelection").click(function(){
		var checked = $j("input[name=id]:checked").size();
		if(checked > 0){
			var actionUrl = $j(this).attr("href");
			$j("form#navForm").attr("action", actionUrl).submit();
			return false;
		}else{
			alert("Please choose a book first");
			return false;
		}
	});
	
	$j(".adminListTable tbody tr:odd").addClass("trStripe");
	$j(".adminListTable tbody tr").hover(function(){
		$j(this).addClass("trHover");
	},function(){
		$j(this).removeClass("trHover");
	});
	
	$j("a[class^=confirmClick]").bind("click", function(){
		var _action = $j(this).attr("class");
		var _actionArr = new Array();
		_actionArr = _action.split('_');
		var _action = _actionArr[1];
		var agree = confirm("Are you sure you wish to "+_action+"?");
		if(agree){
			return true;
		}
		else{
			return false;
		};
	});
});

$j(window).load(function(){
	$j(".warning").fadeOut(1000).fadeIn(1000).animate({opacity:0}, 10000).slideUp();
	$j(".success").animate({opacity:0}, 5000).slideUp();
});
