﻿
var Title = new Array();
Title['/accueil'] = 'Yriase - Accueil';
Title['/contact'] = 'Yriase - Formulaire de contact';
Title['/prestations'] = 'Yriase - Prestations';
Title['/forfaits'] = 'Yriase - Forfaits';
Title['/disponibilite'] = 'Yriase - Disponibilitér';
Title['/devis'] = 'Yriase - Devis en ligne';
Title['/404'] = 'Yriase - Erreur 404';

var Pages = new Array('accueil', 'devis', 'prestations', 'forfaits', 'disponibilite', 'contact', '404');

function onPageLoad(id){
for (i=0; i<Pages.length; i++) { if($("#menu-"+Pages[i])) $("#menu-"+Pages[i]).addClass('page_item page-item-58');
														$("#menu-"+Pages[i]).removeClass('page-item-2 current_page_item');}

if($("#menu-"+id.substring(1, id.length))) { $("#menu-"+id.substring(1, id.length)).removeClass('page_item page-item-58');
											$("#menu-"+id.substring(1, id.length)).addClass('page-item-2 current_page_item'); }
}

function pageload(hash) {
	if($.inArray(hash.substring(1, hash.length), Pages) > -1) {
		if($.jCache.hasItem(hash)) {
			var cache = $.jCache.getItem(hash);
			$("#main").html(cache);
			document.title = Title[hash];
			onPageLoad(hash);
		} else {
		$.ajax({ type: "GET", url: hash.substring(1, hash.length)+'.php', 
		success: function(data){
				$("#main").html(data);
				$.jCache.setItem(hash, data);
				document.title = Title[hash];
				onPageLoad(hash);},
		error: function(){
				$.historyLoad('/404');
			;},
		beforeSend: function() {
			$("#main").html("<img src='http://pro.yriase.fr/images/ajax-loader.gif' alt='Loading' />");
		}
			});
		}
	}
}


function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};


$(document).ready(function(){
 $.historyInit(pageload);
 $("#header-carousel").jcarousel({auto: 1, scroll: 1, wrap: 'last', visible: 5,       
	 initCallback: mycarousel_initCallback });
 
 $("#header img[title]").tooltip({
		tip: '#header-carousel-tip', 
		offset: [10, 2],
		effect: 'slide',
		position: ['bottom', 'center']
	});
});


$(document).ajaxComplete(function(){
 $(".history").click(function(){
   this.rel = this.rel.replace(/history/, '');
   var hash = this.href;
   hash = hash.replace(/^.*#/, '');
   $.historyLoad(hash);
   return false;
 });
 
});

var Types = Array('1', '2', '3', '4', '5', '6', '7', '8');

function showPrestaForm(type) {
	if($.inArray(type, Types) > -1) {
		if($.jCache.hasItem(type)) {
			var cache = $.jCache.getItem(type);
			$("#prestation-type-container").html(cache);
		} else {
		$.ajax({ type: "GET", cache: "false", url: "Prestations/"+type+'.php', 
		success: function(data){
				$.jCache.setItem(type, data);
				$("#prestation-type-container").html(data);
				 },
		error: function(){
				$("#prestation-type-container").html("<tr><td><span style=\"color : red;\">Une erreur est survenue.</span></td></tr>");
			;},
		beforeSend: function() {
			$("#prestation-type-container").html("<img src='http://pro.yriase.fr/images/ajax-loader.gif' alt='Loading' />");
		}
			});
		}
	}
}
