var wid = 0;
$(document).ready(function(){
	$("#header").show();

	/* $("#bloc2").height($("#bloc1").height()); */
	$("#bloc4").show();

	$("#cn0").show();

	// Let's DD_Belate !
	if(typeof DD_belatedPNG != 'undefined') {
		DD_belatedPNG.fix('#logo_zap img, #s, #search_submit, .page_content');
	}

	$("div.casebox div.photoframecase").click(function() {
		//document.location = $(this).next("div").children('a').attr('href') + '#top';
	});



/*
	$('div.photoframecase').hover(function() {
		$('body').css('cursor', 'pointer');
	}, function() {
		$('body').css('cursor', 'default');
	});
*/

	$("a.nswitch").click(function() {
		//alert($(this).attr('id'));
		$(".newsgroup").hide();
		$("#c" + $(this).attr('id')).show('fast');
		return false;
	});
	$("#bookmarkthispage").click(function() {
		addBookmark("Quoifaireaquebec.com " + title, window.location);
		return false;
	});

	$("div.required label").append("<span> *</span>");
	$(".eventphoto img").css('align', 'left');

	$("#photoframe").click(function() {
	//	$(this).focus();
	});

	$("a").click(function() {
		$(this).blur();
	});



	$("a.videos").click(function() {
		id = $(this).attr('id');
		url = webroot + "ajaxs/videos/" + id;
		thisbutton = this;
		$("#uidialog2").dialog({
			bgiframe: true
			,autoOpen: false
			,height: 500
			,width: 'auto'
			,modal: true
			//		,position: [10,5] 
			,bgiframe: true
			,title: 'Vidéo' 
		});

		$.get(url, function(data) {
			// Events_index
			$("#uidialog2").html(data); // le retour ajax c est le formulaire
			$("#uidialog2").show(); // affiche la boite de dialog, car on la cache par defaut
			$("#uidialog2").dialog('open'); // ouvre la boite de dialog
			$("#closedialog2").click(function(){
				$("#uidialog2").dialog('close');
				return false;
			});

		});
		return false;
	});



	$("a.agendaadd, a.agendaremove, a.agendaadd2, a.agendaremove2").click(function() {
		id = $(this).attr('id');
		url = webroot + "ajaxs/agenda/" + id;
		thisbutton = this;
		body = $("body");
		$("#uidialog").dialog({
			bgiframe: true
			,autoOpen: false
			,height: 210
			,width: 350
			,modal: true
			//		,position: [10,5] 
			,bgiframe: true
			,title: 'Message' 
		});

		$.get(url, function(data) {
			// Events_index
			if(data == 1) {
				if($('body').attr('id') == 'Events_view') {
					$("#" + id).text('Retirer de mon agenda');
				}
//				alert($(body).attr('id'));
				$(thisbutton).removeClass(($(body).attr('id') == 'Events_view') ? 'agendaadd2' : 'agendaadd');
				$(thisbutton).addClass(($(body).attr('id') == 'Events_view') ? 'agendaremove2' : 'agendaremove');
			}
			else if(data == 0) {
				if($('body').attr('id') == 'Events_view') {
					$("#" + id).text('Ajouter à mon agenda');
				}
				$(thisbutton).removeClass(($(body).attr('id') == 'Events_view') ? 'agendaremove2' : 'agendaremove');
				$(thisbutton).addClass(($(body).attr('id') == 'Events_view') ? 'agendaadd2' : 'agendaadd');
			}
			else {
				$("#uidialog").html(data); // le retour ajax c est le formulaire
				$("#uidialog").show(); // affiche la boite de dialog, car on la cache par defaut
				$("#uidialog").dialog('open'); // ouvre la boite de dialog
				$("#closedialog").click(function(){
					$("#uidialog").dialog('close');
					return false;
				});
				return false;
			}

			if($('body').attr('id') == 'Users_index') {
				$("#e" + id).hide('slow');
			}
			nbrCountDisplayed = parseFloat($("#nbrEventAgenda").text());
			$("#nbrEventAgenda").text((data == 1) ? nbrCountDisplayed+1 : nbrCountDisplayed-1);

		});
		return false;
	});




	$("table tr:even").addClass("oddrow");
	$(".autoclear").autoclear();

	$('.tags-ajax').tagSuggest({
		url: webroot + 'tags/suggest/'
		,delay: 1000
	});
	$('#ArtistArtists').tagSuggest({
		url: webroot + 'artists/suggest/'
		,separator: ','
		,delay: 1000
	});

//alert(new Date(defaultDateYYYY,defaultDateMM,defaultDateDD));
	$("#datepicker").datepicker({
		dayNamesMin: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam']
		,dateFormat: 'yy-mm-dd' 
		,dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'] 
		,firstDay: 0
		,defaultDate: new Date(defaultDateYYYY,defaultDateMM-1,defaultDateDD)
		//,minDate: 0
//		, showButtonPanel: true
		,prevText: 'Mois pr&eacute;c&eacute;dent'
		,nextText: 'Mois Suivant'
		,monthNames:  ['Janvier','F&eacute;vrier','Mars','Avril','Mai','Juin','Juillet','Ao&ucirc;t','Septembre','Octobre','Novembre','Décembre']  
		,onSelect: function(dateText, inst) {
			url = webroot + "events/date/"+dateText+"/#top";
			document.location = url;			
//			alert(url);
		}
	});
	
	$("#datepicker_calendarFM").datepicker({
		dayNamesMin: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam']
		,dateFormat: 'yy-mm-dd' 
		,dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'] 
		,firstDay: 0
		,defaultDate: new Date(defaultDateYYYY,defaultDateMM-1,defaultDateDD)
		//,minDate: 0
//		, showButtonPanel: true
		,prevText: 'Mois pr&eacute;c&eacute;dent'
		,nextText: 'Mois Suivant'
		,monthNames:  ['Janvier','F&eacute;vrier','Mars','Avril','Mai','Juin','Juillet','Ao&ucirc;t','Septembre','Octobre','Novembre','Décembre']  
		,onSelect: function(dateText, inst) {
			url = "/events/date/"+dateText+"/#top";
			window.open(url);
		}
	});
	$("#datepicker_accueil").datepicker({
		dayNamesMin: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi']
		,dateFormat: 'yy-mm-dd' 
		,dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'] 
		,firstDay: 0
		,defaultDate: new Date(defaultDateYYYY,defaultDateMM-1,defaultDateDD)
		,showOtherMonths: true
		//,minDate: 0
//		, showButtonPanel: true
		,prevText: 'Mois pr&eacute;c&eacute;dent'
		,nextText: 'Mois Suivant'
		,monthNames:  ['Janvier','F&eacute;vrier','Mars','Avril','Mai','Juin','Juillet','Ao&ucirc;t','Septembre','Octobre','Novembre','Décembre']  
		,onSelect: function(dateText, inst) {
			url = webroot + "events/date/"+dateText+"/#top";
			document.location = url;			
//			alert(url);
		}
	});

	$(".datepicker").datepicker({
		 dateFormat: 'yy-mm-dd' 
		,dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'] 
		,dayNamesShort: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam']
		,prevText: 'Pr&eacute;c&eacute;dent'
		,nextText: 'Suivant'
		,changeYear: true
		,dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa']
		,monthNames:  ['Janvier','F&eacute;vrier','Mars','Avril','Mai','Juin','Juillet','Ao&ucirc;t','Septembre','Octobre','Novembre','Décembre']  
		,numberOfMonths: [1, 3]
	});

	// administration
	$("#tabs").tabs();
	$("#tabs").show();

	// By suppling no content attribute, the library uses each elements title attribute by default
	$('li[title], .eventbox input[title], #tabs input[title], #tabs textarea[title], div[title], select[title], img[title]').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		position: {
			corner: {
				target: 'topRight',
				tooltip: 'bottomLeft'
			}
		},

		style: {
			border: {
				radius: 0,
				color: '#303030'
			},
			padding: '3px 7px 3px 7px',
			title: {
				background: '#404040',
				color: '#f3f3f3'
			},
			background: '#505050',
			color: '#f3f3f3'
		}
		// 'dark' // Give it some style
	});
	$('a[href][title], td[title], div#meteo td[title]').qtip({
		content: {
			text: false // Use each elements title attribute
		},
		position: {
			corner: {
				target: 'topLeft',
				tooltip: 'bottomRight'
			}
		},

		style: 'dark' // Give it some style
	});

	bodyId = $("body").attr('id');
	if( (bodyId == 'Users_pw') || (bodyId == 'Users_create') || (bodyId == 'Users_lostpw') || (bodyId == 'Users_login') || (bodyId == 'Users_edit')) {
		destination = $("#top").offset().top;
		$('html').animate({scrollTop : destination},'slow'); 
	}
//	$("body").animate({ scrollTop: destination}, 1100 );
/*
	anchor.init()
	anchor = {
		init : function()  {
			$("a.anchorLink").click(function () {	
				elementClick = $(this).attr("href")
				destination = $(elementClick).offset().top;
				$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination}, 1100 );
			  	return false;
			})
		}
	}
*/
});

function addBookmark(title, url) {
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url,"");
	} else if( document.all ) { //MSIE
		window.external.AddFavorite( url, title);
	} else {
		alert("Sorry, your browser doesn't support this");
	}
}


