﻿jQuery.fn.loadthumb = function(options) {
	options = $.extend({
		 src : ""
	},options);
	var _self = this;
	_self.hide();
	var img = new Image();
	$(img).load(function(){
		_self.attr("src", options.src);
		_self.fadeIn("slow");
	}).attr("src", options.src); 
	return _self;
}

jQuery.fn.loadhref=function(options){
    options = $.extend({
		     href : ""
	    },options);
	    var _self = this;
	    _self.hide();
	    var a = new a();
	    $(a).load(function(){
		    _self.attr("href", options.href);
		    _self.fadeIn("slow");
	    }).attr("href", options.href); 
	    return _self;    
}

$(document).ready(function(){
	 var len  = $(".num > li").length;
	 var index = 0;
	 var adTimer;
	 $(".num li").mouseover(function(){
		index  =   $(".num li").index(this);
		showImg(index);
	 }).eq(0).mouseover();	

	 $('.ad').hover(function(){
			 clearInterval(adTimer);
		 },function(){
			 adTimer = setInterval(function(){
			    index++;
				if(index==len){index=0;}
				showImg(index);				
			  } , 10000);
	 }).trigger("mouseleave");
});

function showImg(index){

		var src = ["images/beijing_index.jpg","images/washington.jpg","images/quebec_index.jpg","images/gta_index.jpg","images/newyork2.jpg"];
		var href = ["#",
		"http://www.wailianvisa.com/project/projectdetail.aspx?nid=509",
		"http://www.wailianvisa.com/news/newsdetail.aspx?nid=494&national=加拿大&nt=11",
		"http://www.wailianvisa.com/minisite/gta/index.aspx",
		"http://www.wailianvisa.com/project/projectdetail.aspx?nid=454"];

		$(".ad img").loadthumb({src:  src[index],href:href[index]});
        $(".ad img").parent("a").attr("href",href[index]);
        $(".ad img").parent("a").attr("target","_blank");
		$(".num li").removeClass("on")
			.eq(index).addClass("on");
}
