/*
 * SillyCube function 1
 *
 * Copyright (c) 2009 SILLYCUBE TECHNOLOGY LIMITED(http://www.sillycube.com)
 * 
 */
function scNavigation(element){
	element.children().filter("div").mouseenter(function(){
		$(this).children().filter("div").slideDown(400);
	}).mouseleave(function(){
		$(this).children().filter("div").fadeOut(100);
	});
}

function scShadow(element){
	element.each(function (){
		var innerHTML = $(this).eq(0).html();
		var innerContent = $("<div class='innerContent' id='innerContent'></div>").append(innerHTML);
		var shadowContent = $("<div class='shadowContent' id='shadowContent'></div>").css("opacity", "0.1").append(innerHTML);
		
		$(this).empty().append(shadowContent).append(innerContent);
		$(this).find("div[id=innerContent]").css("top", -1*innerContent.height()-12).mousemove(function (event){	
			$(this).siblings("div[id=shadowContent]").css("left", ($(this).offset().left+$(this).width()/2 - event.
clientX)/5).css("top", ($(this).offset().top+$(this).height()/2 - event.clientY)/5).effect("scale", {percent: 400, 
direction: "both"},100);
		});
	});
}

function scBold(element){
	var headerText = element.html();
	var newHeaderText = "";
	for(var i = 0; i<headerText.length; i++){
		newHeaderText += "<font>"+headerText.charAt(i)+"</font>";
	}
	element.html(newHeaderText);
	element.find("font").each(function (){
		$(this).mousemove(function (event){
			$(this).css("font-weight", "bold");
		}).mouseout(function (event){
			$(this).css("font-weight", "");
		}).css("position", "relative");
	});
}

function scHighlight(element, bannerValue){
	var dummy = 0;
	if(navigator.appName.indexOf("Micro") != -1 && 
			(navigator.appVersion.indexOf("MSIE 4.0") != -1)||
			(navigator.appVersion.indexOf("MSIE 5.0") != -1)||
			(navigator.appVersion.indexOf("MSIE 6.0") != -1)){
		dummy = 2;
	}
	
	var normalContent = element.attr("id", "normalContent").css("position","relative")
	.css("z-index","2").css("background","url(/images/banner/bw/banner"+bannerValue+".jpg) top");
	
	var highlightContent = element.clone().attr("id", "highlighContent")
		.css("position","relative")
		.css("z-index","1")
		.css("color", reverseColor(element.css("color")))
		//.css("background-color", reverseColor(element.css("background-color")));
		.css("background","url(/images/banner/banner"+bannerValue+".jpg) top");
	element.parent().eq(0).append(highlightContent)
	.mousemove(function (event){
		//$("font[id=debug]").html($(this).find("div[id=normalContent]").css("height")+" || "+event.clientY+" || "+$(this).find("div[id=normalContent]").offset().top+" || "+$(window).scrollTop());
		$(this).find("div[id=normalContent]").css("height", event.clientY - $(this).find("div[id=normalContent]").offset().top+$(window).scrollTop()-dummy);
		$(this).find("div[id=highlighContent]").css("top", -1*(event.clientY - $(this).find("div[id=normalContent]").offset().top+$(window).scrollTop()-dummy));
	}).mouseleave(function (event){
		if(event.clientY<=$(this).find("div[id=normalContent]").offset().top+5){
			$(this).find("div[id=normalContent]").css("height", 0);
			$(this).find("div[id=highlighContent]").css("top", 0);
		}
	})
}

function reverseColor(value){
	var color = new RGBColor(value);
	return new RGBColor("rgb("+(255-color.r)+","+(255-color.g)+","+(255-color.b)+")").toHex();
}
/*
function getTop(e){
	var offset=e.offsetTop;
	if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
	return offset;
}

function getLeft(e){
	var offset=e.offsetLeft;
	if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
	return offset;
}
*/
