$(function(){
	fixedWidth();
	iconsHover();
	buttonHover();
	rowsHover();
	hideMoreWords();
	dataGuard();
});
//---------------------------fixedWidth---------------------------
function fixedWidth(){	
	$('.divContainer').width(screen.width*0.95+'px');
};
//---------------------------iconsHover---------------------------
function iconsHover(){	
	$('img.hover').css('cursor','pointer').each(function(){	
		var src 		= $(this).attr('src');
		var btn_hover	= filePath(src)+fileName(src)+'_o.'+fileType(src);
		var btn			= filePath(src)+fileName(src)+'.'+fileType(src);	
		$(this).hover(	
			function(){ $(this).attr('src',btn_hover);},
			function(){	$(this).attr('src',btn);}
		);
	});
};
//---------------------------buttonHover---------------------------
function buttonHover(){	
	$('input.hover').css('cursor','pointer').each(function(){	
		$(this).hover(	
			function(){ $(this).addClass('buttonHover');},
			function(){	$(this).removeClass('buttonHover');}
		);
	});
};
//---------------------------iconsHover---------------------------
function rowsHover(){	
	$('tr.hover,td.hover').hover(	
		function(){ $(this).addClass('rowsHover');},
		function(){	$(this).removeClass('rowsHover');}
	);
};
//---------------------------hideMoreWords---------------------------
function hideMoreWords(){
	var w = $.browser.mozilla == true?screen.width*0.32+'px':'100%';
	$('div.hideMoreWords,span.hideMoreWords').width(w).each(function(){
		var obj = $(this), he = 40;
		if ($(this).attr('rel') != undefined) {
			he = $(this).attr('rel').split(',').pop();
		}
		if ($(this).height() > he) {
			$(this).height(he+'px').after($(document.createElement('div')).text('...more').css('cursor','pointer').click(function(){
				if ($(this).text()=='...more'){
					$(this).text('...less');
					obj.height('auto');
				}else{
					$(this).text('...more');
					obj.height(he+'px');
				}
			}));
		}
	}).show();
};
//---------------------------dataGuard---------------------------
function dataGuard(){
	$(function(){
	$('#dataGuard .checkAll').click(function(){
		if ($(this).attr('checked')==true){
			$('#dataGuard :checkbox').attr('checked',true); 
		}else{
			$('#dataGuard :checkbox').removeAttr('checked');
		}
	});
	$('#dataGuard :submit[name="priorityAll"],:image[name="priorityAll"]').click(function(){
		$('#dataGuard :checkbox').attr('checked',true); 
	});
	$('#dataGuard .confirm').click(function(){
		var msg = $(this).attr('label')?$(this).attr('label'):'Are you sure to confirm?';
		if (confirm(msg)) {
			return true;
		}else{
			return false;
		}
	});
});
}
//---------------------------loadPiece---------------------------
function loadPiece(href,divName) {    
    $(divName).load(href, {}, function(){
        var divPaginationLinks = divName+" a.ajaxLink";
        $(divPaginationLinks).click(function() {     
            var thisHref = $(this).attr("href");
            loadPiece(thisHref,divName);			
            return false;
        });
    });
}
//----------------------- filePath -----------------------
function filePath(url){	
	var filepath = '', last = url.lastIndexOf("\/"), last_str = url.lastIndexOf("\?");
	if (last_str!=-1){			
		filepath		= url.substring(last_str,last+1);
	}else{
		filepath		= url.substring(0,last+1);
	}
	return filepath
};
//----------------------- fileFullName -----------------------
function fileFullName(url){	
	return url.split('/').pop(); 
};
//----------------------- fileName -----------------------
function fileName(url){	
	return url.split('/').pop().split('.').shift();
};
//----------------------- fileType -----------------------
function fileType(url){	
	return url.split('/').pop().split('.').pop(); 	
};
//----------------------- ajax -----------------------
var ajax = function (url, elements, loading){	
		if (url!=undefined && elements!=undefined){		
			loading = loading==undefined?'0':loading;				
			$.ajax({
				url: url,
				type: 'POST',
				data: null,
				beforeSend: function(){	
				}, 
				error: function(msg) {
					alert(msg);
				},
				success: function(response) {
					if (typeof(elements)=='object'){
						$(elements).html(response);
					}else if (typeof(elements)=='string'){
						$('#'+elements).html(response);
					}
				}
			});
		}
	};
	
var ajax2 = function (url, elements, loading){	
		if (url!=undefined && elements!=undefined){		
			loading = loading==undefined?'0':loading;				
			$.ajax({
				url: url,
				type: 'POST',
				data: null,
				beforeSend: function(){	
				}, 
				error: function(msg) {
					alert(msg);
				},
				success: function(response) {
					if (typeof(elements)=='object'){
						$(elements).before(response);
					}else if (typeof(elements)=='string'){
						$('#'+elements).before(response);
					}
				}
			});
		}
	};
