/*
King du granite.
global.js
26/10/11	v3.0
*/

function init()
{
	$('a[rel*=external]').live('click', function() {window.open(this.href); return false; });
}

function initHome()
{
	$('.homethumbs').hover ( function()
	{
		$(this).addClass('homethumbshover');
	}, function ()
	{
		$(this).removeClass('homethumbshover');
	});

	$('.homethumbs').click ( function ()
	{
		window.location = $('a', this).attr('href');
		return false;
	});

	$('#projet').hover ( function()
	{
		$(this).addClass('projetover');
	}, function ()
	{
		$(this).removeClass('projetover');
	});

	$('#projet').click ( function ()
	{
		window.location = $('a', this).attr('href');
		return false;
	});

	$('#bannerinfo').hover ( function()
	{
		$(this).addClass('bannerover');
	}, function ()
	{
		$(this).removeClass('bannerover');
	});

	$('#bannerinfo').click ( function ()
	{
		window.location = $('a', this).attr('href');
		return false;
	});

	$('.news').hover ( function()
	{
		$(this).addClass('newsover');
	}, function ()
	{
		$(this).removeClass('newsover');
	});

	$('.news').click ( function ()
	{
		window.location = $('a', this).attr('href');
		return false;
	});

	$('#slideshow').cycle(
	{
		fx: 'fade',
		sync: 1,
		speed: 600,
		timeout: 4000,
		pager: '#slidernav'
	});
}

function initApercu()
{
	$('.pub').hover ( function()
	{
		$(this).addClass('pubhover');
	}, function ()
	{
		$(this).removeClass('pubhover');
	});

	$('.pub').click ( function ()
	{
		window.location = $('a', this).attr('href');
		return false;
	});

	$('.projet').hover ( function()
	{
		$(this).addClass('projethover');
	}, function ()
	{
		$(this).removeClass('projethover');
	});

	$('.projet').click ( function ()
	{
		window.location = $('a', this).attr('href');
		return false;
	});
}

function initRightCol()
{
	$('.pub').hover ( function()
	{
		$(this).addClass('pubhover');
	}, function ()
	{
		$(this).removeClass('pubhover');
	});

	$('.pub').click ( function ()
	{
		window.location = $('a', this).attr('href');
		return false;
	});

	$('.projet').hover ( function()
	{
		$(this).addClass('projethover');
	}, function ()
	{
		$(this).removeClass('projethover');
	});

	$('.projet').click ( function ()
	{
		window.location = $('a', this).attr('href');
		return false;
	});
}

function initGranite()
{
	for ( idx = 0; idx < colorGranite.length; idx++ )
	{
		str = '<div class="tuile letter' + colorGranite[idx][LETTERIDX] + ' ' + colorGranite[idx][COLORIDX] + '"><a onclick="chooseGranite(' + idx + ');" href="#colorPane" rel="prettyPhoto" title="' + colorGranite[idx][NAMEIDX] + '"><img src="../images/prod/granite/bthumbs/' + colorGranite[idx][CLOSEUPIDX] + '.jpg" width="95" height="95" alt="' + colorGranite[idx][NAMEIDX] + '" /></a></div>' ;
		$('#tuiles').append(str);
	}

	$('#granitecolor').change( function()
	{
		$("#graniteletter").val('');
		currentColor = $(this).val();
		if ( currentColor == '' )
			$('.tuile').show();
		else
		{
			displayGraniteColor(currentColor);
			$('.tuile:not(.' + currentColor + ')' ).hide();
			$('.' + currentColor).show();
		}
	});

	$('#graniteletter').change( function()
	{
		$("#granitecolor").val('');
		currentLetter = $(this).val();

		if ( currentLetter == '' )
			$('.tuile').show();
		else
		{
			displayGraniteLetter(currentLetter);
			$('.tuile:not(.letter' + currentLetter + ')' ).hide();
			$('.letter' + currentLetter).show();
		}
	});

	$("a[rel^='prettyPhoto']").prettyPhoto(
	{
		showTitle:false,
		default_width: 700,
		theme:'dark_square'
	});
}

function initMarble()
{
	for ( idx = 0; idx < colorMarble.length; idx++ )
	{
		str = '<div class="tuile letter' + colorMarble[idx][LETTERIDX] + ' ' + colorMarble[idx][COLORIDX] + '"><a onclick="chooseMarble(' + idx + ');" href="#colorPane" rel="prettyPhoto" title="' + colorMarble[idx][NAMEIDX] + '"><img src="../images/prod/marble/bthumbs/' + colorMarble[idx][CLOSEUPIDX] + '.jpg" width="95" height="95" alt="' + colorMarble[idx][NAMEIDX] + '" /></a></div>' ;
		$('#tuiles').append(str);
	}

	$('#marblecolor').change( function()
	{
		$("#marbleletter").val('');
		currentColor = $(this).val();
		if ( currentColor == '' )
			$('.tuile').show();
		else
		{
			displayMarbleColor(currentColor);
			$('.tuile:not(.' + currentColor + ')' ).hide();
			$('.' + currentColor).show();
		}
	});

	$('#marbleletter').change( function()
	{
		$("#marblecolor").val('');
		currentLetter = $(this).val();

		if ( currentLetter == '' )
			$('.tuile').show();
		else
		{
			displayMarbleLetter(currentLetter);
			$('.tuile:not(.letter' + currentLetter + ')' ).hide();
			$('.letter' + currentLetter).show();
		}
	});

	$("a[rel^='prettyPhoto']").prettyPhoto(
	{
		showTitle:false,
		default_width: 700,
		theme:'dark_square'
	});
}

function initQuartz()
{
	for ( idx = 0; idx < colorQuartz.length; idx++ )
	{
		str = '<div class="tuile letter' +
				colorQuartz[idx][LETTERIDX] + ' ' +
				colorQuartz[idx][COLORIDX] + '"><a onclick="chooseQuartz(' + idx + ');" href="#colorPane" rel="prettyPhoto" title="' +
				colorQuartz[idx][NAMEIDX] + '"><img src="../images/prod/quartz/bthumbs/' +
				colorQuartz[idx][CLOSEUPIDX] + '.jpg" width="95" height="95" alt="' +
				colorQuartz[idx][NAMEIDX] + '" /></a></div>' ;
		$('#tuiles').append(str);
	}

	$('#quartzcolor').change( function()
	{
		$("#quartzletter").val('');
		currentColor = $(this).val();
		if ( currentColor == '' )
			$('.tuile').show();
		else
		{
			displayQuartzColor(currentColor);
			$('.tuile:not(.' + currentColor + ')' ).hide();
			$('.' + currentColor).show();
		}
	});

	$('#quartzletter').change( function()
	{
		$("#quartzcolor").val('');
		currentLetter = $(this).val();

		if ( currentLetter == '' )
			$('.tuile').show();
		else
		{
			displayQuartzLetter(currentLetter);
			$('.tuile:not(.letter' + currentLetter + ')' ).hide();
			$('.letter' + currentLetter).show();
		}
	});

	$("a[rel^='prettyPhoto']").prettyPhoto(
	{
		showTitle:false,
		default_width: 700,
		theme:'dark_square'
	});
}

function initGallery ( isLangFr )
{
	if ( isLangFr )
	{
		if ( location.hash == '#salle-de-bain' )
			currentPanel = 'btn2' ;
		else if ( location.hash == '#exterieur' )
			currentPanel = 'btn3' ;
		else
		{
			location.hash == '#cuisine' ;
			currentPanel = 'btn1' ;
		}
	}
	else
	{
		if ( location.hash == '#bathroom' )
			currentPanel = 'btn2' ;
		else if ( location.hash == '#exterior' )
			currentPanel = 'btn3' ;
		else
		{
			location.hash == '#kitchen' ;
			currentPanel = 'btn1' ;
		}
	}

	$('#panel_' + currentPanel).show();
	$('#' + currentPanel).addClass('select');

	$('#subnav a').click( function ()
	{
		newPanel = $(this).attr('id');

		if ( newPanel != currentPanel )
		{
			$('#'+newPanel).addClass('select');
			$('#'+currentPanel).removeClass('select');

			$('#panel_' + currentPanel).fadeOut('slow');
			$('#panel_' + newPanel).fadeIn('slow');
			currentPanel = newPanel;
		}
	});

	$('#galleryCuisine').cycle({
		nowrap: true,
		fx:      'fade',
		timeout:  0,
		prev:    '#prevc',
		next:    '#nextc',
		pager:   '#galleryNavCuisine',
		before: onBeforeC,
		after:   onAfterC,
		onPrevNextEvent: onPrevNextC,
		pagerAnchorBuilder: pagerFactoryC
	});

	$('#galleryBain').cycle({
		nowrap: true,
		fx:      'fade',
		timeout:  0,
		prev:    '#prevb',
		next:    '#nextb',
		pager:   '#galleryNavBain',
		before: onBeforeB,
		after:   onAfterB,
		pagerAnchorBuilder: pagerFactoryB
	});

	function pagerFactoryC(idx, slide) 	{ return '#galleryNavCuisine li:eq(' + idx + ') a' };
	function pagerFactoryB(idx, slide) 	{ return '#galleryNavBain li:eq(' + idx + ') a' };

	function onAfterC()
	{
		$('#galleryCuisineTitle').html(this.alt);
	}
	
	function onBeforeC()
	{		
		id = parseInt(this.id.substring(3));
		if ( id == 1 )	{ $('#prevc').hide(); }
		else			{ $('#prevc').show(); }
		if ( id == nbImgCuisine )	{ $('#nextc').hide(); }
		else			{ $('#nextc').show(); }
	}

	function onAfterB() 			 	
	{ 
		$('#galleryBainTitle').html(this.alt);		
	}
	
	function onBeforeB()
	{
		id = parseInt(this.id.substring(3));		
		if ( id == 1 )			{ $('#prevb').hide(); }
		else					{ $('#prevb').show(); }
		if ( id == nbImgBain )	{ $('#nextb').hide(); }
		else					{ $('#nextb').show(); }
	}

	function onPrevNextC (isNext, zeroBasedSlideIndex, slideElement)
	{
		id = parseInt(slideElement.id.substring(3));

		if ( isNext )
		{
			if ( id%4 == 1 ) cCarousel.scroll(id);
		}
		else
		{
			if ( id > 20 )
			{
				cCarousel.scroll(21-3);
			}
			else
			{
				if ( id%4 == 1)
				{
					cCarousel.scroll(id-3);
				}
			}
		}
	}

	$('#galleryNavCuisine').jcarousel(
	{
		initCallback: cuisine_initCallback,
		scroll: 4
	});

	$('#galleryNavBain').jcarousel(
	{
		// Att Css Hide Prev/Next Btn
		//wrap: 'circular'
	});
}

function cuisine_initCallback(carousel)
{
	cCarousel = carousel;
}

function initNouvelle ( isLangFr )
{
	if ( isLangFr )
	{
		if ( location.hash == '#archives' )
			currentPanel = 'btn2' ;
		else
		{
			location.hash == '#nouvelles' ;
			currentPanel = 'btn1' ;
		}
	}
	else
	{
		if ( location.hash == '#archives' )
			currentPanel = 'btn2' ;
		else
		{
			location.hash == '#news' ;
			currentPanel = 'btn1' ;
		}
	}

	$('#panel_' + currentPanel).show();
	$('#' + currentPanel).addClass('select');

	$('#subnav a').click( function ()
	{
		newPanel = $(this).attr('id');

		if ( newPanel != currentPanel )
		{
			$('#'+newPanel).addClass('select');
			$('#'+currentPanel).removeClass('select');

			$('#panel_' + currentPanel).fadeOut('slow');
			$('#panel_' + newPanel).fadeIn('slow');
			currentPanel = newPanel;
		}
	});

	$('.newslist a').click ( function ()
	{
		newPanel = $(this).attr('id');
		if ( newPanel != currentPanel )
		{
			$('#panel_' + currentPanel).fadeOut('fast');
			$('#panel_' + newPanel).fadeIn('fast');
			currentPanel = newPanel;
		}
	});

	$('.backtoarchives').click ( function ()
	{
		newPanel = 'btn2';
		if ( newPanel != currentPanel )
		{
			$('#panel_' + currentPanel).fadeOut('fast');
			$('#panel_' + newPanel).fadeIn('fast');
			currentPanel = newPanel;
		}
	});
}

function initContact( isLangFr )
{
	if ( isLangFr )
	{
		if ( location.hash == '#demande' )
			currentPanel = 'btn2' ;
		else
		{
			location.hash == '#coordonnees' ;
			currentPanel = 'btn1' ;
		}
	}
	else
	{
		if ( location.hash == '#request' )
			currentPanel = 'btn2' ;
		else
		{
			location.hash == '#coordinates' ;
			currentPanel = 'btn1' ;
		}
	}

	$('#panel_' + currentPanel).show();
	$('#' + currentPanel).addClass('select');


	$('#subnav a').click( function ()
	{
		newPanel = $(this).attr('id');

		if ( newPanel != currentPanel )
		{
			$('#'+newPanel).addClass('select');
			$('#'+currentPanel).removeClass('select');

			$('#panel_' + currentPanel).fadeOut('slow');
			$('#panel_' + newPanel).fadeIn('slow');
			currentPanel = newPanel;
		}
	});
}
