/* *
 * ------------------No reload link-----------------
 * @author: Leysam Rosario 
 * @version: 0.1
 * @how to use: just add no-reload class to "a" tag and the href should be #name
 * @thanks to: me
*/

var dom = 'http://www.tempomayfair.co.uk/';

function unmask_hash(hash_hash){
	hash = hash_hash;
	final = explode('#',hash)
	return final[1];
}

var process;
function noRlink(status){
	if(status){
		$('a').click(function(){
				if($(this).attr('class') == 'no-reload'){
					$('.add-space').fadeOut(100);
					dom = dom;
					a_loc = $(this).attr('rel');
					loc = dom+a_loc;
					hash = $(this).attr('href').replace(/#/gi,'');
					
					if(hash == 'gallery'){
						
						$('#content-container').animate({
														width: '160px'
													}/*, {duration:'fast', complete:function(){ $('#content-container').css("margin-left", "-260px");}}*/)
						
						$('#sample-content').animate({
														width: '160px'
													})
						
						$('#apps div').animate({
														width: '160px'
													})
						
						$('#apps').animate({
														width: '130px'
													})
						
						$('.c-right').animate({
														width: '160px'
													})
						
					}else{
						if($('.c-right').width() != '420'){
							$('#content-container').css("margin-left", "0px")
							
							$('#content-container').animate({
														width: '420px'
													})
							
							$('#sample-content').animate({
														width: '420px'
													})
							
							
							$('#apps div').animate({
															width: '420px'
														})
							
							$('#apps').animate({
															width: '420px'
														})
						
							
							$('.c-right').animate({
															width: '420px'
														})
						}
					}
					window.location = $(this).attr('href');
						//Change id to "active" if clicked
						set_id = 'active';		
						a = document.getElementsByTagName('a');
						doc_hash = document.location.hash.replace(/#/gi,'')
						//show_preloader(true,'loading',hash+' page'); 
						
						for(i=0; i < a.length; i++){
							if(a[i].className == 'no-reload'){
								a[i].id = '';
								if(unmask_hash(a[i].href) == doc_hash){
									a[i].id = set_id;
								}
							}
						}
					//execute link without window reloading 
					$.get(loc,function(con){
						$('#content-container').html('<div id="sample-content"><div class="add-space">'+con+'</div></div>');
						$('.add-space').fadeIn(100);
						$('#sample-content').jScrollPane();
						//loaded!
						process = 1;
						//show_preloader(false,'loading',doc_hash+' page done!');
						//hide_preloader();
						process = 0;
					});
						
					return false;
				
				//load the link of the class is not "no-link"
				}else{
					return true;
				}
			
		})
	}
}

function load_hash(trigger){
	if(trigger){
		doc_hash = document.location.hash.replace(/#/gi,'')
		a = document.getElementsByTagName('a');
		for(i=0; i < a.length; i++){
			if(a[i].className == 'no-reload'){
				if(unmask_hash(a[i].href) == doc_hash){
					a[i].id = 'active';
					connect_to = a[i].rel;
					$.get(connect_to,function(con){										
						$('#content-container').html('<div id="sample-content"><div class="add-space">'+con+'</div></div>').fadeIn(100);	
						$('#sample-content').jScrollPane();
						
						if(doc_hash == 'gallery'){
						/*/$('#content-container').css({"marginLeft":"-260px", "position":"relative"});*/
						$('#content-container').animate({
														width: '160px'
													})
						
						$('#sample-content').animate({
														width: '160px'
													})
						
						$('#apps div').animate({
														width: '160px'
													})
						
						$('#apps').animate({
														width: '160px'
													})
						
						$('.c-right').animate({
														width: '160px'
													})
						
					}
						$('#bg-resize img').ready(function(){	
								//your process
						});
					});
					
				}
			}
		}
	}
}

