
jQuery(function() {
	
	// • • • • • • • • • • • • • • • Carregando pagina ao clicar no menu
    var hash = window.location.hash.substr(1);
	var paginas = new Array("oxford", "peeptoes", "rasteiras", "sapatilhas");
	var numero = Math.floor((Math.random() * 3));
	
	jQuery(window).load(function() {
		
		if(hash == '') {
			loadColecoes(paginas[numero]+'.php', 550);
			jQuery('li#'+paginas[numero]).children('a').addClass('onView');
			jQuery('li#verao2012').children('a').addClass('onView');
		}
		
	});
	
	var href = jQuery('.menu li a').each(function() {
		var href = jQuery(this).attr('href');
		
		if(hash == href.substr(0, href.length-4)) {
			var toLoad = hash+'.php';
			jQuery('.menu li a').removeClass('onView');
			TrocaCor(toLoad);
			
			jQuery('#main').animate({ height:0}, 'slow', function() {
				switch(toLoad) {
					case 'quemSomos.php':
						loadContent(toLoad, 400);
						jQuery('li#quemSomos').children('a').addClass('onView');
					break;
					
					case 'ondeComprar.php':
						loadContent(toLoad, 600)
						jQuery('li#ondeComprar').children('a').addClass('onView');
					break;
					
					case 'contato.php':
						loadContent(toLoad, 750)
						jQuery('li#contato').children('a').addClass('onView');
					break;
					// • • • • • • • • • • • • • • carregar coleções
					case 'oxford.php':
						loadColecoes(toLoad, 550);
						jQuery('li#oxford').children('a').addClass('onView');
						jQuery('li#verao2012').children('a').addClass('onView');
					break;
					
					case 'peeptoes.php':
						loadColecoes(toLoad, 550)
						jQuery('li#peeptoes').children('a').addClass('onView');
						jQuery('li#verao2012').children('a').addClass('onView');
					break;
					
					case 'sapatilhas.php':
						loadColecoes(toLoad, 550)
						jQuery('li#sapatilhas').children('a').addClass('onView');
						jQuery('li#verao2012').children('a').addClass('onView');
					break;
					
					case 'rasteiras.php':
						loadColecoes(toLoad, 550)
						jQuery('li#rasteiras').children('a').addClass('onView');
						jQuery('li#verao2012').children('a').addClass('onView');
					break;
				}
			});
		}
	});
	
	jQuery('.menu li a').click(function() {
		window.location.hash = jQuery(this).attr('href').substr(0, jQuery(this).attr('href').length-4);
		var toLoad = jQuery(this).attr('href');
		
		jQuery('.menu li a').removeClass('onView');
		
		jQuery('#main').animate({ height:0}, 'slow', function() {
			switch(toLoad) {
				case 'quemSomos.php':
					loadContent(toLoad, 400);
					jQuery('li#quemSomos').children('a').addClass('onView');
				break;
				
				case 'ondeComprar.php':
					loadContent(toLoad, 600);
					jQuery('li#ondeComprar').children('a').addClass('onView');
				break;
				
				case 'contato.php':
					loadContent(toLoad, 750);
					jQuery('li#contato').children('a').addClass('onView');
				break;
				// • • • • • • • • • • • • • • carregar coleções
				case 'oxford.php':
					loadColecoes(toLoad, 550);
					jQuery('li#oxford').children('a').addClass('onView');
					jQuery('li#verao2012').children('a').addClass('onView');
				break;
				
				case 'peeptoes.php':
					loadColecoes(toLoad, 550);
					jQuery('li#peeptoes').children('a').addClass('onView');
					jQuery('li#verao2012').children('a').addClass('onView');
				break;
				
				case 'sapatilhas.php':
					loadColecoes(toLoad, 550);
					jQuery('li#sapatilhas').children('a').addClass('onView');
					jQuery('li#verao2012').children('a').addClass('onView');
				break;
				
				case 'rasteiras.php':
					loadColecoes(toLoad, 550);
					jQuery('li#rasteiras').children('a').addClass('onView');
					jQuery('li#verao2012').children('a').addClass('onView');
				break;
			}
		});
		
		return false;
	});
	// • • • • • • • • • • • • • • • • • carrega pagina
	function loadContent(jPagina, jAltura) {
		TrocaCor(jPagina);
		jQuery('#main').load(jPagina, '', function() {
			jQuery('#main').animate({ height:jAltura }, 'slow');
		});
		jQuery('#menuColecoes ul').slideUp('fast', function() {
			jQuery(this).parents('#menuColecoes').animate({'height':20}, 'medium')
		});
	}
	// • • • • • • • • • • • • • • • • • carrega coleção
	function loadColecoes(jPagina, jAltura) {
		TrocaCor(jPagina);
		jQuery('#main').load(jPagina, '', function() {
			jQuery('#main').animate({ height:jAltura }, 'slow');
		});
		jQuery('#menuColecoes').animate({height:60}, 'medium', function() {
			jQuery(this).children('ul').slideDown('medium')
		});
	}
	// • • • • • • • • • • • • • • • • • Mouse over/out menu de coleções
	jQuery("#menuColecoes ul li a").mouseenter(function() {
		var $thisColecao = jQuery(this).attr('href');
		
		switch($thisColecao) {
			case 'oxford.php':
				jQuery(this).parents('#menuColecoes').stop().animate({ backgroundColor: "#8D8D60"});
				jQuery('#verao2012 a').stop().animate({ color: "#8D8D60"});
			break;
			
			case 'peeptoes.php':
				jQuery(this).parents('#menuColecoes').stop().animate({ backgroundColor: "#608DBA"});
				jQuery('#verao2012 a').stop().animate({ color: "#608DBA"});
			break;
			
			case 'sapatilhas.php':
				jQuery(this).parents('#menuColecoes').stop().animate({ backgroundColor: "#E78D06"});
				jQuery('#verao2012 a').stop().animate({ color: "#E78D06"});
			break;
			
			case 'rasteiras.php':
				jQuery(this).parents('#menuColecoes').stop().animate({ backgroundColor: "#E7608D"});
				jQuery('#verao2012 a').stop().animate({ color: "#E7608D"});
			break;
		}
	});
	
	jQuery("#menuColecoes").mouseleave(function() {
		var $onOnView = jQuery('#menuColecoes a.onView').attr('href')
		TrocaCor($onOnView);
	});
	
});

// • • • • • • • • • • • • • • Verifica a URL e guarda numa Array
function getUrlVars() {
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	
    for(var i = 0; i < hashes.length; i++) {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}
// • • • • • • • • • • • • • • troca a cor da barra de acordo com a coleção
function TrocaCor($trocador) {
	var $this = jQuery('#menuColecoes ul li a');
	
	switch($trocador) {
		case 'oxford.php':
			$this.parents('#menuColecoes').stop().animate({ backgroundColor: "#8D8D60"});
			jQuery('#verao2012 a').stop().animate({ color: "#8D8D60"});
		break;
		
		case 'peeptoes.php':
			$this.parents('#menuColecoes').stop().animate({ backgroundColor: "#608DBA"});
			jQuery('#verao2012 a').stop().animate({ color: "#608DBA"});
		break;
		
		case 'sapatilhas.php':
			$this.parents('#menuColecoes').stop().animate({ backgroundColor: "#E78D06"});
			jQuery('#verao2012 a').stop().animate({ color: "#E78D06"});
		break;
		
		case 'rasteiras.php':
			$this.parents('#menuColecoes').stop().animate({ backgroundColor: "#E7608D"});
			jQuery('#verao2012 a').stop().animate({ color: "#E7608D"});
		break;
		
		default:
			$this.parents('#menuColecoes').stop().animate({ backgroundColor: "#66CCFF"});
			jQuery('#verao2012 a').stop().removeAttr('style');
		break;
	}
}



