jQuery.extend({
	ajaxcall:function(url, data, callback, dataType, errorCallback, timeout){
		data = {
			'url':url,
			'cache':false,
			'data':data,
			'dataType':'json',
			'type':'POST',
			'success':callback
		};
		
		if(typeof(dataType)!='undefined'){
			data.dataType = dataType;
		}
		
		if(typeof(timeout)!='undefined'){
			data.timeout = timeout;
		}
		
		if(typeof(errorCallback)!='undefined'){
			data.error = errorCallback;
		}
		
		jQuery.ajax(data);
	}
});

jQuery.fn.extend({
	'switching':function($speed, $slideSpeed, $showText){
		if(typeof($speed)=='undefined'){
			$speed = 2000;
		}
		
		if(typeof($slideSpeed)=='undefined'){
			$slideSpeed = 500;
		}
		
		if(typeof($showText)=='undefined'){
			$slideSpeed = false;
		}
		
		var $switchingList = $(this);
		if($showText){
			$switchingList.append('<div class="description"></div>');
		}

		var $itemWidth = $switchingList.find('.container a:first').width();
		var $itemHeight = $switchingList.find('.container a:first').height();
		var $itemCount = $switchingList.find('.container a').size();
		$switchingList.data({
			'stop':false,
			'index':0,
			'itemWidth':$itemWidth,
			'itemHeight':$itemHeight,
			'itemCount':$itemCount
		});
		$switchingList.find('.container').css('width', (($itemWidth + 1) * $itemCount) + 'px');
		$switchingList.find('.container').after('<div class="switchPager"></div>');
		for(var i=1;i<=$itemCount;i++){
			$switchingList.find('.switchPager').append('<a href="javascript:void(0);">' + i + '</a>');
		}
		
		$switchingList.find('.container a').add('.switchPager a').mouseover(function(event){
			event.stopPropagation();
			$switchingList.data('stop', true);
		}).mouseout(function(event){
			event.stopPropagation();
			$switchingList.data('stop', false);
		});
		
		$switchingList.find('.switchPager a').each(function(index){
			$(this).click(function(){
				$switchingList.data('index', index);
				$container = $switchingList.find('.container');
				$container.stop(true, true);
				$container.animate({
					'marginLeft':'-' + ($itemWidth * index) + 'px'
				}, $slideSpeed);
				$switchingList.find('.switchPager a').removeClass('current').eq($switchingList.data('index')).addClass('current');
				$item = $switchingList.find('.container a').eq(index);
				$switchingList.find('.description').html($item.find('img').attr('title'));
			});
		});
		
		$switchingList.find('.switchPager a:first').click();
		
		setInterval(function(){
			if($switchingList.data('stop')==false){
				$index = $switchingList.data('index') + 1;
				var $itemCount = $switchingList.data('itemCount');
				if($index>=$itemCount){
					$index = 0;
				}
				$switchingList.find('.switchPager a').eq($index).click();
			}
		}, $speed);
		
		return $(this);
	}
});

jQuery.extend({
	'loadImage':function (url, callback, error) {
	    var img = new Image();
	    img.src = url;
	    if (img.complete) {
	        return callback && callback(img.width, img.height);
	    }
	    
        img.onload = function () {
        	callback && callback(img.width, img.height);
            img.onload = null;
        };
        
        img.onerror = function () {
            error && error();
        };
	}
});

function evtPagerSelector(){
	$index = $(this).val();
	$url = $(this).parent().nextAll('a.page_' + $index).attr('href');
	document.location = $url;
}

jQuery(function($){
	//$("ul.slidingMenu").slidingMenu();
	$('#topMenu .menuItem>a').hover(function(){
		$(this).parent().siblings().removeClass('current');
		$(this).parent().addClass('current');
	});
	
	$(".pager .pagerSelector").change(evtPagerSelector);
});

function request(paras){ 
	var url = location.href; 
	var paraString = url.substring(url.indexOf("?")+1,url.length).split("&"); 
	var paraObj = {};
	for (i=0; j=paraString[i]; i++){ 
		paraObj[j.substring(0,j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=")+1,j.length); 
	} 
	var returnValue = paraObj[paras.toLowerCase()]; 
	if(typeof(returnValue)=="undefined"){ 
		return ""; 
	}else{ 
		return decodeURIComponent(returnValue); 
	} 
}
