﻿$.fn.extend({
	allenMenu: function() {
		$(this).children('ul').children('li').hover(
			function() {
				if(!$(this).children('ul').hasClass('focus')) {
					$(this).addClass('focus');
					$(this).children('ul:first').stop(true, true).animate({ height:'show' }, 'fast');
				}
			},
			function() {
				$(this).removeClass('focus');
				$(this).children('ul:first').stop(true, true).animate({ height:'hide', opacity:'hide' }, 'slow');
			}
		);
		$(this).children('ul').children('li').children('ul').hover(
			function() {
				$(this).addClass('focus');
			},
			function() {
				$(this).removeClass('focus');
			}
		);
	}
});

$.fn.extend({
	allenSlide: function() {
		var ads = $(this).find('ul:first li');
		var name = $(this).attr('id');
		var n = ads.length;
		var w = ads.width();
		var h = ads.height();
		var clicked = false;
		var t = 4000;
		var lt = 5000;
		var speed = 'slow';
		var curPage = 0;
		
		//$(this).children('ul:first').append($(this).find('ul:first li:first').clone());
		
		$(this).width(w).height(h);
		$(this).css('overflow', 'hidden');
		$(this).css('position', 'relative');
		$(this).children('ul:first').width(w * (n + 1));
		var pages = $('<div class="slide-page"></div>');
		for(var i = 1; i <= n; i++) {
			var el = $('<a href="#" id="' + name + '-page-' + i + '">' + i + '</a>');
			eval('el.click(function(){ clicked = true; slideTo(' + i + '); return false; });');
			pages.append(el);
		}
		$(this).append(pages);
		$('#' + name + '-page-1').parent().addClass('on');
		autoSlide();
		
		/* Fade Version
		*/
		function slideTo(page) {
			curPage = page;
			var ml = -1 * w * (page - 1);
			$('#' + name).find('li:eq('+(curPage-1)+')').stop();
			if(page > n) {
				page = 1;
				curPage = 1;
			}
			$('#' + name).find('li').each(function() {
				if($(this).css("display") != "none") {
					//$(this).css('z-index', '2');
					$(this).fadeOut(speed);
				}
			});
			//$('#' + name).find('li:eq('+(page-1)+')').css('z-index', '1');
			$('#' + name).find('li:eq('+(page-1)+')').fadeIn(speed);
			$('#' + name).find('.slide-page > a').removeClass('on');
			$('#' + name + '-page-' + curPage).addClass('on');
		}

		/* Slide Version
		function slideTo(page) {
			curPage = page;
			var ml = -1 * w * (page - 1);
			$('#' + name).children('ul:first').stop();
			if(page > n) {
				curPage = 1;
			} else if(page == 2 && !clicked) {
				$('#' + name).children('ul:first').css('margin-left', '0px');
			}
			$('#' + name).children('ul:first').animate({ marginLeft: ml }, speed);
			$('#' + name).find('.slide-page > a').removeClass('on');
			$('#' + name + '-page-' + curPage).addClass('on');
		}
		*/
		
		function autoSlide() {
			var tp = curPage;
			if(!clicked) {
				slideTo(tp + 1);
				eval('setTimeout(function() { autoSlide(); }, ' + t + ');');
			} else {
				clicked = false;
				eval('setTimeout(function() { autoSlide(); }, ' + lt + ');');
			}
		}

	}
});
function show_back(a){
	a.style.background = "url(images/back_03.jpg)";
	}
function hidd_back(a){
	a.style.background = "none";
	}



$(document).ready(function() {
//Set Default State of each portfolio piece
$(".paging").show();
$(".paging a:first").addClass("active");

//Get size of images, how many there are, then determin the size of the image reel.
var imageWidth = $(".window").width();
var imageSum = $(".image_reel img").size();
var imageReelWidth = imageWidth * imageSum;

//Adjust the image reel to its new size
$(".image_reel").css({'width' : imageReelWidth});

//Paging + Slider Function
rotate = function(){    
var triggerID = $active.attr("rel") - 1; //Get number of times to slide
var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

$(".paging a").removeClass('active'); //Remove all active class
$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)

//Slider Animation
$(".image_reel").animate({ 
left: -image_reelPosition
}, 1000 );

}; 

//Rotation + Timing Event
rotateSwitch = function(){        
play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
$active = $('.paging a.active').next();
if ( $active.length === 0) { //If paging reaches the end...
$active = $('.paging a:first'); //go back to first
}
rotate(); //Trigger the paging and slider function
}, 3000); //Timer speed in milliseconds (3 seconds)
};

rotateSwitch(); //Run function on launch

//On Hover
$(".image_reel a").hover(function() {
clearInterval(play); //Stop the rotation
}, function() {
rotateSwitch(); //Resume rotation
});    

//On Click
$(".paging a").click(function() {    
$active = $(this); //Activate the clicked paging
//Reset Timer
clearInterval(play); //Stop the rotation
rotate(); //Trigger rotation immediately
rotateSwitch(); // Resume rotation
return false; //Prevent browser jump to link anchor
});    

});
<!--//友情链接js效果-->
//$(document).ready(function() {
//	$("#pre_but").click(function(){
//		$("#pre_app_tr").toggle();						
//		})
//	})
function change(a) 
{
    $("#pre_app_tr"+a).toggle(); 
}
//function change(){
//	if(document.getElementById("pre_app_tr").style.display = "none"){
//		 document.getElementById("pre_app_tr").style.display = "table";
//		}
//	}

var currslid = 0;
var slidint;
function setfoc(id){
var focpic = document.getElementById("focpic");
 focpic.src = picarry[id];
 document.getElementById("foclnk").href = lnkarry[id];

 currslid = id;
 for(i=0;i<=7;i++){
  document.getElementById("tmb"+i).className = "thubpic";
 };
 document.getElementById("tmb"+id).className ="thubpiccur";
 focpic.style.visibility = "hidden";
 focpic.filters[0].Apply();
 if (focpic.style.visibility == "visible") {
  focpic.style.visibility = "hidden";
  	if(navigator.appName == "Microsoft Internet Explorer"){ 
  focpic.filters.revealTrans.transition=23;
  focpic.filters.revealTrans.duration=10; 
  }
  	else{
		focpic.filters.revealTrans.transition=23;
		}
 }
 else {
  focpic.style.visibility = "visible";
  focpic.filters[0].transition=23;
 }
 focpic.filters[0].Play();
 stopit();
}

function playnext(){
 if(currslid==7){
  currslid = 0;
 }
 else{
  currslid++;
 };
 setfoc(currslid);
 playit();
}
function playit(){
 slidint = setTimeout(playnext,8000);
}
function stopit(){
 clearTimeout(slidint);
 }
window.onload = function(){
 playit();
}
