/**
 * Created by JetBrains PhpStorm.
 * User: ekko3
 * Date: 9/14/11
 * Time: 5:47 PM
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function(){


var first_time = true;

    $("a.fancybox").fancybox({
        padding:            0,
        cyclic:             true,
        overlayColor:       '#000',
        overlayOpacity:     0.5,
        transitionIn:       'elastic',
        transitionOut:      'elastic',
        scrolling:          'no',
        onComplete: function(){

            first_time = false;
            url = $("#c_grille_name").val();
            url = url.replace(/^.*#/, '');
            $.history.load('!/'+url);


            function hashCallback(url) {
              if(/^!/.test(url)) {
                url = url.substring(2);
                //...
              }
            }


            var element = location.href;
            var total_url = element.split('/');


            _gaq.push(['_trackPageview', '/'+total_url[3]+'/'+total_url[4]+'/'+total_url[5]+'/'+ url]);


        },
        onClosed: function() {
            url = '';
            $.history.load(url);

            _gaq.push(['_trackPageview', '/grilles/']);
            return false;
        }
    });



    $.history.init(function(url){

        if (url == ''){
        }else {

            $("a.fancybox").each(function(){
                if ($(this).attr('hdata')== "#"+url){
                    if (first_time){
                        $(this).click();
                        first_time = false;
                    }
                }
            })
        }

    },{unescape: "/,&"});


    $('input[safari]:checkbox').checkbox({cls:'jquery-safari-checkbox'});



     $('.tags input').change( function() {

         if ($(this).attr('class')=="ft-all"){
             if ($(this).is(':checked')){
                 $('.tags input').each (function() {
                     $(this).prop('checked', false);
                 });
                 $('.ft-all').prop('checked', true);
             }
         }else{
             $('.ft-all').prop('checked', false);
         }
          $('.results > li').hide();
          $('.tags input').each( function() {
              if ($(this).is(':checked')){
               $('.'+$(this).attr('class')).show();
              }
          });
     });

    

});


