﻿/* IE6訊息提示，設置對話框全局默認配置，樣式設定*/
(function($, window, artDialog, undefined) {
	
	var config = artDialog.defaults;
	
	config['skin'] = 'opera';// black , green ,default...
	config['path'] = 'plugins/artDialog';
	
	config['drag'] = true;
	config['showTemp'] = 100000;
	
	config['title'] = '網頁訊息';
	config['okVal'] = '確定';
	config['cancelVal'] = '取消';
	
	var link = document.createElement('link');
	link.rel = 'stylesheet';
	link.href = config['path'] + '/skins/' + config['skin'] + '.css';
	document.getElementsByTagName('head')[0].appendChild(link);
	
	artDialog.IE6A = function (options) {
		
		var opt = options || {},
			api;
		
		var config = {
			title: false,
			fixed: true,
			lock: true,
			padding: 0,
			opacity: .7
		};
		
		for (var i in opt) {
			if (config[i] === undefined) config[i] = opt[i];
		};
		
		return artDialog(config);
	}
	
	artDialog.IE6B = function (options) {
		
		var opt = options || {},
			api, aConfig, hide, wrap, top,
			duration = 800;
				
		var config = {
			id: 'Notice',
			left: '100%',
			top: '100%',
			padding: 0,
			fixed: true,
			title: false,
			drag: false,
			resize: false,
			follow: null,
			lock: false,
			init: function(here) {
				api = this;
				aConfig = api.config;
				wrap = api.DOM.wrap;
				top = parseInt(wrap[0].style.top);
				hide = top + wrap[0].offsetHeight;
				
				wrap.css('top', hide + 'px')
					.animate({top: top + 'px'}, duration, function() {
						opt.init && opt.init.call(api, here);
					});
			},
			close: function(here){
				wrap.animate({top: hide + 'px'}, duration, function() {
					opt.close && opt.close.call(this, here);
					aConfig.close = $.noop;
					api.close();
				});
				
				return false;
			}
		};	
		
		for (var i in opt) {
			if (config[i] === undefined) config[i] = opt[i];
		};
		
		return artDialog(config);
	};	
})(window.jQuery || window.art, this, this.artDialog);

jQuery(document).ready(function() {	

  swfobject.embedSWF('themes/default/images/logo.swf', 'logoSWF', '140', '90', '10', 'themes/default/images/expressInstall.swf', {}, {wmode: 'transparent', menu: false}, {});

  // img
	jQuery('.imgOpa').animate({ opacity: 0.7 });
  jQuery('.imgOpa').each(function() {
    jQuery(this).hover(
      function() {
        jQuery(this).stop().animate({ opacity: 1.0 }, 100);
        },function() {
      jQuery(this).stop().animate({ opacity: 0.7 }, 100);
    })
  });

	//Search
	jQuery('input[name="keywords"]').bind('focus', function() {
		jQuery(this).removeClass("inputText");
	}).bind('updateState', function() {
		if (this.value.length == 0) {
			jQuery(this).addClass("inputText");
		}
		else {
			jQuery(this).removeClass("inputText");
		}
	}).bind('blur', function() {
		jQuery(this).trigger('updateState');
  }).trigger('updateState');
	
	// PNG 在 IE5.5 IE6 透明及滑鼠改變圖像
  jQuery('img[src$="_out.png"], input[src$="_out.png"]')
    .ifixpng()
    .css({cursor: 'pointer'})
    .hover(
      function () {
        jQuery(this).iunfixpng();
        var img_src = this.src;
        if (img_src != '_out.png') {
          var over_src = img_src.substring(0, img_src.lastIndexOf('_out.png')) + '_over.png';
          if (over_src != '_over.png') {
            jQuery(this).attr('src', over_src).ifixpng();
          }
        }
      },
      function () {
        jQuery(this).iunfixpng();
        var img_src = this.src;
        if (img_src != '_over.png') {
          var out_src = img_src.substring(0, img_src.lastIndexOf('_over.png')) + '_out.png';
          if (out_src != '_out.png') {
            jQuery(this).attr('src', out_src).ifixpng();
          }
        }
      }
    );

  // 全部 PNG 在 IE5.5 IE6 透明
  jQuery('img[src$=".png"], input[src$="_out.png"], .png').ifixpng().iunfixpng().ifixpng();

  // GIF 滑鼠改變圖像
  jQuery('img[src$="_out.gif"], input[src$="_out.gif"]')
    .css({cursor: 'pointer'})
    .hover(
      function () {
        var img_src = this.src;
        if (img_src != '_out.gif') {
          var over_src = img_src.substring(0, img_src.lastIndexOf('_out.gif')) + '_over.gif';
          if (over_src != '_over.gif') {
            jQuery(this).attr('src', over_src);
          }
        }
      },
      function () {
        var img_src = this.src;
        if (img_src != '_over.gif') {
          var out_src = img_src.substring(0, img_src.lastIndexOf('_over.gif')) + '_out.gif';
          if (out_src != '_out.gif') {
            jQuery(this).attr('src', out_src);
          }
        }
      }
    );

  // JPG 滑鼠改變圖像
  jQuery('img[src$="_out.jpg"], input[src$="_out.jpg"]')
    .css({cursor: 'pointer'})
    .hover(
      function () {
        var img_src = this.src;
        if (img_src != '_out.jpg') {
          var over_src = img_src.substring(0, img_src.lastIndexOf('_out.jpg')) + '_over.jpg';
          if (over_src != '_over.jpg') {
            jQuery(this).attr('src', over_src);
          }
        }
      },
      function () {
        var img_src = this.src;
        if (img_src != '_over.jpg') {
          var out_src = img_src.substring(0, img_src.lastIndexOf('_over.jpg')) + '_out.jpg';
          if (out_src != '_out.jpg') {
            jQuery(this).attr('src', out_src);
          }
        }
      }
    );
		

	// IE6 彈跳訊息
	if ((jQuery.browser.msie && jQuery.browser.version <= 6) && jQuery.cookie("IE6") == null) {
		jQuery.dialog.IE6B({
			content: jQuery('#domMessage')[0],
			time: 5,
			init: function(here){
				var api = this;
				jQuery('#domMessage input[type="button"]').click(function() {
					api.close();
				});
				jQuery.cookie("IE6", 1, { expires: 1}); 
			}
		});
	}

})

function addBookmarkForBrowser(sTitle, sUrl) {

  var userAgent = navigator.userAgent.toLowerCase();
  var browser = {
    version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1],
    safari: /webkit/.test( userAgent ),
    opera: /opera/.test( userAgent ),
    msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
    mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
  };
	
  if (browser.mozilla) {
    addBookmarkForBrowser = function(sTitle, sUrl) {
      window.sidebar.addPanel(sTitle, sUrl, "");
    };
  }
  else if (browser.msie) {
    addBookmarkForBrowser = function(sTitle, sUrl) {
      window.external.AddFavorite(sUrl, sTitle);
    };
  }
  else if (browser.safari) {
    addBookmarkForBrowser = function() {
      alert("do it yourself");
    };
  }
  else {
    addBookmarkForBrowser = function() {
      alert("do it yourself");
    };
  }
  return addBookmarkForBrowser(sTitle, sUrl);
}

