// JavaScript Document
window.addEvent('domready', function(){
	var sectionact;
	var section;
/*
	var transit = 0;
	var legals = 0;
	$('legals_menu').fade(0);
	$('legals_menu').style.display = "block";
*/
	var slider = new Fx.Slide('subsection',{duration: 700, transition: Fx.Transitions.Expo.easeOut}).hide();
	$('subsection').style.display = "block";
	resetDisplays();
/*	
	$('campaign').addEvent('click', function(e) { window.location = "/campaign/"; });
	
	$('radio').addEvent('click', function(e) { window.open("http://www.pepejeans.com/radio/",null,"height=180,width=622,location=no,status=no,menubar=no,resizable=no"); });
	
	$('kidsSub1').addEvent('click', function(e) { window.location = "/kids/images"; });
	$('kidsSub2').addEvent('click', function(e) { window.location = "/kids/makingof"; });
	
	$('companySub1').addEvent('click', function(e) { window.location = "/company/history"; });
	$('companySub2').addEvent('click', function(e) { window.location = "/company/jobs"; });
	$('companySub3').addEvent('click', function(e) { window.location = "/company/stores"; });
	$('companySub4').addEvent('click', function(e) { window.location = "/events/"; });
	$('companySub5').addEvent('click', function(e) { window.location = "/company/contact"; });
	
	$('andywarhol').addEvent('click', function(e){ window.location = "/andywarhol/"; });
	
	$('collectionSub1').addEvent('click', function(e) { window.location = "/collection/men"; });
	$('collectionSub2').addEvent('click', function(e) { window.location = "/collection/woman"; });
	$('collectionSub3').addEvent('click', function(e) { window.location = "/collection/kids"; });
	
	$('freshair').addEvent('click', function(e){ window.location = "/freshair/"; });
*/
	$('denimSub1').addEvent('click', function(e){ window.location = "denimimages.html"; });
	$('denimSub2').addEvent('click', function(e){ window.location = "denimmakingof.html"; });
	$('denimSub3').addEvent('click', function(e){ window.location = "denimfitgallery.html"; });
	$('denimSub4').addEvent('click', function(e){ window.location = "denimcloseups.html"; });
	
	
	
	$('homeMenu').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
	$('denimMenu').addEvent('mouseover', function(e){
		section = "denim";
		slider.slideOut();
	});
	$('storesMenu').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
	$('stockistsMenu').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
	$('subscribeMenu').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
	$('offersMenu').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
	$('collectionMenu').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
	$('contactMenu').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
/*
	$('collectionImg').addEvent('mouseover', function(e){
			section = "collection";
			slider.slideOut();
	});
	
	$('kidsImg').addEvent('mouseover', function(e){
			section = "kids";
			slider.slideOut();
	});
	
	$('companyImg').addEvent('mouseover', function(e){
			section = "company";
			slider.slideOut();
	});
	$('andywarhol').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
	$('freshair').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});
*/
	$('content').addEvent('mouseover', function(e){
		section = "";
		slider.slideOut();
	});

	$('subsection').addEvent('mouseover', function (e){
		section = sectionact;
	});
	
	
	
	slider.addEvent('complete', function() {
		/*if (slide.open == true)
		{
			if (section != sectionact) { slider.slideIn(); }
			else { section = sectionact; }
		}
		else
		{
			if (section != sectionact)
			{
				resetDisplays();
				if (section == "denim") { document.getElementById("denimSub").style.display = "block"; }
				if (section == "kids") { document.getElementById("kidsSub").style.display = "block"; }
				if (section == "company") { document.getElementById("companySub").style.display = "block"; }
				if (section == "collection") { document.getElementById("collectionSub").style.display = "block"; }
				if (section != "") { slider.slideIn(); }
			}
			else { sectionact = section; }
		}*/
		if (sectionact != section) {
			if (slider.open == false) {
				resetDisplays();
				if (section == "denim") { document.getElementById("denimSub").style.display = "block"; }
/*				
				if (section == "kids") { document.getElementById("kidsSub").style.display = "block"; }
				if (section == "company") { document.getElementById("companySub").style.display = "block"; }
				if (section == "collection") { document.getElementById("collectionSub").style.display = "block"; }
*/
				if (section != "") { slider.slideIn(); }
				sectionact = section;
			}
			else {
				slider.slideOut();
			}
		}
		else if (slider.open == false) {
			resetDisplays();
				if (section == "denim") { document.getElementById("denimSub").style.display = "block"; }
/*				
				if (section == "kids") { document.getElementById("kidsSub").style.display = "block"; }
				if (section == "company") { document.getElementById("companySub").style.display = "block"; }
				if (section == "collection") { document.getElementById("collectionSub").style.display = "block"; }
*/
				if (section != "") { slider.slideIn(); }
			slider.slideOut(); }
	});
/*
	$('esp').addEvent('click', function() {
		setLanguage("es");
		window.location.href = window.location.href;
	});
	$('eng').addEvent('click', function() {
		setLanguage("en");
		window.location.href = window.location.href;
	});
*/	
	/*
	// Legals and register
	*/
/*	
	$('legals').addEvent('click', function(e) {
		e.stop();
		if (legals == 0) {
			legals = 1;
			$('legals_menu').fade(1);
		}
		else {
			legals = 0;
			$('legals_menu').fade(0);
		}
	});
	$('legals_copyright').addEvent('click', function(e) {
		e.stop();
		resetLegals();
		$('copyright_popup').style.display = "block";
	});
	$('legals_privacy').addEvent('click', function(e) {
		e.stop();
		resetLegals();
		$('privacy_popup').style.display = "block";
	});
	$('register_nl').addEvent('click', function(e) {
		e.stop();
		resetLegals();
		$('register_popup').style.display = "block";
	});
	$('copyright_close').addEvent('click', function(e) {
		e.stop();
		resetLegals();
	});
	$('privacy_close').addEvent('click', function(e) {
		e.stop();
		resetLegals();
	});
	
	var resetLegals = function() {
		$('copyright_popup').style.display = "none";
		$('privacy_popup').style.display = "none";
		$('register_popup').style.display = "none";
	}
	
	var createForm = function() {
		req = new Request({url:'/php/registerPopup_' + language + '.php'});
		var log = $('register_popup').empty().addClass('ajax-loading');
		req.onSuccess = function(responseText, responseXML) {
			log.removeClass('ajax-loading');
			$('register_popup').set('html',responseText);
			$('reg_male').addEvent('click', function () {
				$('reg_gender_input').value = "Male";
				$('reg_male').style.background = "#666666";
				$('reg_female').style.background = "none";
			});
			$('reg_female').addEvent('click', function () {
				$('reg_gender_input').value = "Female";
				$('reg_female').style.background = "#666666";
				$('reg_male').style.background = "none";
			});
			$('register_close').addEvent('click', function(e) {
				e.stop();
				resetLegals();
			});
			$('reg_conds').style.cursor = "pointer";
			$('reg_conds').addEvent('mouseover', function() { $('conditions_popup').style.display = "block" });
			$('reg_conds').addEvent('mouseout', function() { $('conditions_popup').style.display = "none" });
			registerForm();
		}
		req.send();
	}
	
	var setLanguage = function(idioma) {
		Cookie.dispose('language');
		var myCookie = Cookie.write('language', idioma, {path: '/', duration: 90});
	}
	
	// Submit en ajax
	var registerForm = function() {
		$('register_news').addEvent('submit', function(e) {
			new Event(e).stop();
			var sender = new Request({url:'/php/registerPopup_' + language + '.php',data: this});
 			sender.onSuccess = function(responseText, responseXML){
				  $('register_popup').set('html', responseText);
				  $('reg_male').addEvent('click', function () {
						$('reg_gender_input').value = "Male";
						$('reg_male').style.background = "#666666";
						$('reg_female').style.background = "none";
					});
					$('reg_female').addEvent('click', function () {
						$('reg_gender_input').value = "Female";
						$('reg_female').style.background = "#666666";
						$('reg_male').style.background = "none";
					});
					$('register_close').addEvent('click', function(e) {
						e.stop();
						resetLegals();
					});
					$('reg_conds').style.cursor = "pointer";
					$('reg_conds').addEvent('mouseover', function() { $('conditions_popup').style.display = "block" });
					$('reg_conds').addEvent('mouseout', function() { $('conditions_popup').style.display = "none" });
				  registerForm();
			};
			sender.send();
		});
	}
	setLanguage(language);
	createForm();
*/	
}); 

function resetDisplays() {
	document.getElementById("denimSub").style.display = "none";
/*
	document.getElementById("kidsSub").style.display = "none";
	document.getElementById("companySub").style.display = "none";
	document.getElementById("collectionSub").style.display = "none";
*/
}
