jQuery(document).ready(function () {
	
	//png底圖修復
	if ($.browser.msie && $.browser.version.substring(0,1) === '6') {
	$('img, .container, #IndexMusicTheory, #IndexQA, .Courses, .News, .AboutUs, .VideoAlbum, .Careers, .Board, .Contactus,#IndexKnowledgeBg,ul#topnav a,#Left,div.photo a span,#productDivIn table tr td,#flowtabs li').supersleight();
	}else{
	//美化表單元件
	$("select, input , textarea").uniform();
	}

	//圓角
//	if ($.browser.msie !== true) {
//     $("Div#DetailTitle").corner("5px"); 	//Ｄetail頁面標題圓角5度
//	};

    

	//上方超級選單
	//On Hover Over
	if ( $(this).find("#topnav").length > 0 ) {
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo(0, 0.9).show(); //Find sub and fade it in(
			
		//用函數來計算ul的總寬度
		(function($) { 
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				//計算 row
				$(this).find("ul").each(function() { //for each ul...
					rowWidth += $(this).width(); //將所有ul的寬度加總
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //如果 .row 存在..
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() { //for each row...
				$(this).calcSubWidth(); //Call function to calculate width of all ul's
				//Find biggest row
				if(rowWidth > biggestRow) {
					biggestRow = rowWidth;
				}
			});
			//Set width
			$(this).find(".sub").css({'width' :biggestRow}); //Set width
			$(this).find(".row:last").css({'margin':'0'}); //Kill last row's margin
			
		} else { //If row does not exist...
			
			$(this).calcSubWidth(); //Call function to calculate width of all ul's
			$(this).find(".sub").css({'width' : rowWidth}); //Set Width
			
		}
	}
	//On Hover Out
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo(1, 0, function() { //Fade to 0 opactiy
		  $(this).hide(); //after fading, hide it
	  });
	}
 
    //客製化設定檔參數
	var config = {    
		 sensitivity: 2, // 數值 = 靈敏度設置 (必須1或更高，原設值2)    
		 interval: 100, // 數值 = 滑鼠移到選單後幾秒才會展開(原設值100)   
		 over: megaHoverOver, // function = onMouseOver callback (REQUIRED)    
		 timeout: 100, // 數值 = 滑鼠移出後延遲多久才消失(原設值500)
		 out: megaHoverOut // function = onMouseOut callback (REQUIRED)    
	};
 
	//$("ul#topnav li .sub").css({'opacity':'0'}).corner("bottom"); //Fade sub nav to 0 opacity on default，corner("bottom")增加子選單下方圓角;
	$("ul#topnav li").hoverIntent(config); //觸發超級選單客製化設定檔
	
	$('div.row').last().remove();
	
	}
    //超級選單結束
	
	//在要顯示信箱的地方加上一個class="getmail"的標籤，
	//如：信箱：<span class="getmail">載入中，請稍後... </span>
    var mailhead = "SERVICE";
    var mailbody = "@SUNHOUSE-FURNITURE.COM.TW";
	if ( $(".getmail").length > 0 ) { //如果當前元素存在...
		setTimeout(function(){
			$('.getmail').hide().html(mailhead + mailbody).fadeIn('slow');
		}, 6000);
	}
	
	//啟動首頁Tab頁籤功能
	$("#flowtabs").tabs(".panes", { history: true });
	




//防複製
if ( $("#IndexCentered").length <= 0 ) { //如果當前元素存在...
	$("body").get(0).oncontextmenu = function() { return false; };
	$("body").keydown(function(event) {
		//alert(window.event);
		var forbiddenKeys = new Array('c', 'x', 'v');
		var keyCode = (event.keyCode) ? event.keyCode : event.which;
		var isCtrl;
		isCtrl = event.ctrlKey
		if (isCtrl) {
			for (i = 0; i < forbiddenKeys.length; i++) {
				if (forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
					//alert('You are prompted to type this twice for a reason!');
					return false;
				}
			}
		}
		return true;
	 
	});

};



}); //$(document).ready end

	//左側目錄用
	max_list = $('.MainLi').length;
	slideSpeed = 500;
	complete = new Array();
	for ( var i = 0; i < max_list;i++){
		complete[i] = false;
	}
	
function leftmenu(num){
	LMobj = $('.MinorPri').eq(num);
	LMimg = $('.MainLi img').eq(num);
	if (complete[num]){
		LMimg.attr({ src: "../images/All/Expand.png" });
		LMobj.slideUp(slideSpeed, function() {
			 complete[num] = false;
		});
	}else{
		LMimg.attr({ src: "../images/All/Collapse.png"});
		LMobj.slideDown(slideSpeed, function() {
			 complete[num] = true;
		});
	}
}

	//在頁面引入此js，
	//然後在要替換的<img>標籤內，加上 onerror="errorimg(this)"
		var rimg = "../images/Sample.jpg"; //當無圖片時，顯示的替代圖
	function errorimg(x, y) {
		if (y == null) {
			x.src = rimg;
		}
		else {
			x.src = y;
		}
	}
	




	
$(document).ready(function() {
	//LOGIN按鈕
	$('#login_BTN input').mouseover(function() {
		$(this).css({ 'background-image':'url(../images/Login/loginButtonHover.png)'});
	});
	$('#login_BTN input').mouseout(function() {
		$(this).css({ 'background-image':'url(../images/Login/loginButtonLink.png)'});
	});
	//FackBookPoint
	$('#FackBookPoint').click(function (){
		//$('#FackBookPointMsg').html("");
		 $.ajax({
			 url: '../../AJAX/action_addFackPoint.php',
			 cache: false,
			 dataType: 'html',
			 type:'POST',
			 data: { 
			 //article_tags: $('#article_tags').val(),
			 //article_mailTo: $('#article_mailTo').val()
			 }, 
			 error: function(xhr) {
			 },
			 success: function(response) {
					$('#mPoint').html(response);
					$('#mPointAdd').fadeIn(500).fadeOut(3000);
			 }
		});
	});
	//臉書按鈕
	$('.connect_widget_like_button').click(function (){
		 $.ajax({
			 url: '../../AJAX/action_addFackPoint.php',
			 cache: false,
			 dataType: 'html',
			 type:'POST',
			 data: { }, 
			 error: function(xhr) { },
			 success: function(response) {
					$('#mPoint').html(response);
					$('#mPointAdd').fadeIn(500).fadeOut(3000);
			 }
		});
	});
	//臉書按鈕2
	$('.socialPlugins ul li').click(function (){
		 $.ajax({
			 url: '../../AJAX/action_addFackPoint.php',
			 cache: false,
			 dataType: 'html',
			 type:'POST',
			 data: { }, 
			 error: function(xhr) { },
			 success: function(response) {
					$('#mPoint').html(response);
					$('#mPointAdd').fadeIn(500).fadeOut(3000);
			 }
		});
	});	
});
//更換驗證碼圖片(登入會員使用)
function RefreshImageLogin(valImageId) {
	var objImage = document.images[valImageId];
	if (objImage == undefined) {
		return;
	}
	var now = new Date();
	objImage.src = objImage.src.split('?')[0] + '?width=60&height=28&characters=5&s=' + new Date().getTime();
}
