/*!
 * GesWeb jquery Library for strid using jQuery v1.3.2
 * http://www.obtic.ch/
 *
 * Copyright (c) 2010 Obtic Sarl
 *
 * Date: 2010-07-08 (Fri, 9 July 2010)
 */
    $(function() {

						$('area').qtip({
                position : {
                  target : 'mouse',
                  adjust : { mouse: true }
                },
                style: { 
                  name: 'dark' 
								}
            });
						
						// Select Combo
            $("#gw-sel-commune").change(function(event){
              self.location.href=$(this).val();			
            });
						
            $('#gw-map-nvd').maphilight({
                fill: true,
                fillColor: '000000',
                fillOpacity: 0.3,
                stroke: true,
                strokeColor: 'ffffff',
                strokeOpacity: 1,
                strokeWidth: 1,
                fade: true,
                alwaysOn: false
            });

        // Dechets Tooltip 
//				alert($('.tooltip > a[href]').val());
        $(".item > img[title]").tooltip({
				    delay:100,
				    opacity:1,
				    tip: '#gw-dechet-tooltip',
				    cancelDefault:true,
				    onBeforeShow:function(){
									$('#gw-dechet-tooltip').html(this.getTrigger().next().html());
				    }
        });

        // Dechets Scroller
        $("div.scrollable")
				      .scrollable({
                size:8
						  })
							.autoscroll({
								steps:2,
								interval:3000
              });
//							.circular()

        // News Scroller
				$('div.headline').removeClass('gw-hidden');// if javascript enable on customer, show all headline
        $('#gw-scroller').scrollup({
              speed:            6000,
              containerheight:   200,
              containerwidth:    240
        });
	
        // Footer place
        resizePage();

        $(window).resize(function() {
          resizePage();	
        });

//        Jquery Accordion
//        $("#accordion").accordion({
//          animated: 'bounceslide'
//        });

        // Faq open/close effect
        $('.gw-faq-question').click(function() {
          if ( $(this).find("div:first").hasClass("ui-icon-triangle-1-e") ) {
            $(this).find("div:first").removeClass("ui-icon-triangle-1-e").addClass("ui-icon-triangle-1-s");
          }
          else {
            $(this).find("div:first").removeClass("ui-icon-triangle-1-s").addClass("ui-icon-triangle-1-e");
          }
							
          $(this).next().toggle("normal");
            return false;
        }).next().hide();

        // Quick Search
        $('#submit-search').click(function(){
//							 $('#SearchForm').attr("action","page.asp?id=<%'=PageSearch%>&amp;query=<%'=Query%>");
               $('#SearchForm').submit();
        });
			
        $('#SearchBox').focus(function(e){
               if($(this).attr("value") == "<%=Query%>") $(this).attr("value", "");
        });
						
        $('#SearchBox').blur(function(e){
               if($(this).attr("value") == "") $(this).attr("value", "<%=Query%>");
        });

			// Add picto to link
        $('#gw-text a,#gw-connexe-block a').filter(function() {
               return this.hostname && this.hostname !== location.hostname;
        }).after(' <img src="../Themes/common/images/external.png" alt="external link" />');   
        
				$("#gw-text a[href$='.pdf'],#gw-connexe-block a[href$='.pdf']").after(' <img src="../Themes/common/images/pdf.png" alt="fichier acrobat pdf" />');   

      });
      //JQuery
			
			// position baground picture & footer
      // if text container is less than browser height minus header
      // -> Stretch picture to the bottom 
      // -> move footer to bottom
      function resizePage() {

        // Windows Height
        var maxWindowHeight = ( $(window).height() > 680 ) ? 680 : $(window).height()

        // Avaiable Height
        var maxAvaiableHeight = maxWindowHeight - $('#gw-header-bgr').height();
				
				// Hauteur Max des block (Menu Left ou Texte ou connexe) + marge haut
        var marginTopHeight		= parseFloat($('#gw-text').css('marginTop'));
        var footerHeight			= $('#gw-footer-block').height();
				var maxContentHeight  =  Math.max(
				                          $('#gw-content-block').height(), 
				                          $('#gw-connexe-block').height() 
																				+ marginTopHeight 
																				+ parseFloat($('#gw-connexe-block').css('marginBottom')) 	//8
																				+ parseFloat($('#gw-connexe-block').css('paddingBottom')) //8 
				                        ); 

				// Footer placement (margin between content ans footer)
        var footerMarginTop 	= 0;
        if( maxAvaiableHeight-maxContentHeight > footerHeight ) {

          // Stretch background picture
          $('#gw-bgr-content').height( maxAvaiableHeight );

          // Move footer
          $('#gw-footer-block').css('top', maxAvaiableHeight-maxContentHeight-footerHeight);
        }
        else {
          $('#gw-footer-block').css('marginTop', 10);
        }
      }

