$(document).ready(function() {  
  
  pageHit();
  
/* START NEWS */  
  //hide alles
  $('[class^=full_news_tekst_leesVerder]').hide();  

  // toggle news bericht
  $('[class^=leesVerder]').click(function() {
      // toggle news bericht

      var $this = $(this);
      var x = $this.attr("className");   
      $('.news_tekst_' + x).slideToggle(1);        // close small
      $('.full_news_tekst_' + x).slideToggle(400);   // open full               
      return false;
  });
/* END NEWS */
 
 
 
 
/* START PHOTOWORKS */
    // styling van de catnaam
    $('[class^=catNaam]').css({"width" : "122px",
                               "height" : "17px",
                               "lineHeight" : "1.4em",    /* 1.5em */
                               "padding" : "0 0 0 5px",
                               "float" : "left"                        
                             });                  
                             
    // styling van de items in het pulldown menu    
    $('[class^=pullDownText]').css({"width" : "143px",
                                    "height" : "17px",
                                    "lineHeight" : "1.4em",
                                    "background" : "#751D1C",
                                    "border" : "0",
                                    "borderTop" : "1px solid #FFF",
                                    "padding" : "0 0 0 5px",
                                    "color" : "#FFF",
                                    "float" : "left"                                    
                                    });
    // do not display links
    $('[class^=links]').css({"display" : "none"});


    // container voor de catnaam         
    for(var x=1;x<4;x++) {
        $('#pullDownContainer' + x).css({ "width" : "148px",                                                                   
                                          "height" : "17px",   
                                          "lineHeight" : "1.2em",
                                          "background" : "#751D1C",                        
                                          "border" : "0",
                                          "borderTop" : "1px solid #461917",
                                          "margin" : "5px 0 0 0",
                                          "float" : "left"
                                     });        
    }         
                                    
                                    

                            

    /* HOVERS */     
    $('[class^=catNaam]').mouseover(function() {

        var $this = $(this);
        var x = $this.attr("className");

        $("."+x).css({'color' : '#FFF',
                      'fontWeight' : 'bold',
                      'cursor' : 'pointer' });
                                            
    });
    
    $('[class^=catNaam]').mouseout(function() {

        var $this = $(this);
        var x = $this.attr("className");
        $("."+x).css({'color' : '#FFF',
                      'fontWeight' : 'normal',
                      'cursor' : 'pointer' });
    });    
        
    
    // items in het menu    
    $('[class^=pullDownText]').mouseover(function() {

        var $this = $(this);
        var x = $this.attr("className");
        
        $("."+x).css({'color' : '#FFF',
                      'cursor' : 'pointer',
                      'background' : '#571818' });            
    });

    $('[class^=pullDownText]').mouseout(function() {        

        var $this = $(this);
        var x = $this.attr("className");

        $("."+x).css({'color' : '#FFF',
                      'cursor' : 'pointer',
                      'background' : '#751D1C' });                                  
    });   

        
    
    /* CLICKS */    
    $("[class^=catNaam]").click(function() {         

        var $this = $(this);
        var x = $this.attr("className");
       
        // haal het getal op aan het einde van de string
        var getal = x.charAt(x.length-1);
                                                                    
        // als er een menu open staat klap die in en open het menu dat op geklikt is
        //$("[class^=links]").slideUp("fast");
        
        $(".links"+getal).css({"width" : "140px"});
        $(".links"+getal).toggle("normal"); 
        
        
        
        // check aan de hand van het aantal karakters hoe hoog de container moet zijn 
        getCatItems(getal, x);    // cat nummer en catnaam       

                              
        /**
        *  haal de items op die in de categorie ziten        
        *  dit is nodig omdat er voor sommige items een grotere height moet gezet moet worden
        */ 
        function getCatItems(catId, sCatNaam) {      
            method    = 'GET';
            var oRequest = new cRequest();
            var sGet = '?catId='+ catId;
            oRequest.sUrl     = 'photoworks/getCatItems.php' + sGet;
            oRequest.sType  = method;
                        
            //console.log(oRequest.getContent().responseText);
            var data = eval(oRequest.getContent().responseText); 

            
            //console.log(sCatNaam);
            if(sCatNaam == 'catNaam1') {
                var catnaam = 'year';                
            }            
            else if(sCatNaam == 'catNaam2') {
                var catnaam = 'location';                
            }            
            else if(sCatNaam == 'catNaam3') {
                var catnaam = 'commission';                
            }
                               
                               
            for(var i=0; i<data.length; i++) {                
                //console.log(data[i].item + ' - ' +data[i].item.length);
                var item = data[i].item; 
                if(item.length > 24) {         

                    // START HACK
                    var sURL = window.location.href;        
                    var aURLParts = sURL.split('photoworks/');    
                    var aURLParams = aURLParts[1].split('/');                     
                                    
                    if(typeof(aURLParams[1]) != 'undefined') {
                        
                        if(aURLParams[1] != 'location' && aURLParams[1] != 'year' && aURLParams[1] != 'commission') {
                        //console.log('test1' + aURLParams[1]);    
                            // misschien forloop

                            $('.sItem0').css({ "height" : "27px" });  
                            $('.pullDownText' + catnaam + '0').css({"width" : "143px",
                                                                  "height" : "27px",
                                                                  "lineHeight" : "1.2em",
                                                                  "background" : "#751D1C",
                                                                  "border" : "0",
                                                                  "borderTop" : "1px solid #FFF",
                                                                  "padding" : "0 0 0 5px",
                                                                  "color" : "#FFF",
                                                                  "float" : "left"                                    
                                                                 });                                                        
                        }
                    }                                          

                    // EIND HACK 
                    
                                        
                                                                            
                    // hier wordt de hoogte van een item contiainer bepaald
                    $('.links3 .sItem' + i).css({"height" : "27px", "color" : "blue"});                                                                                          
                    
                    //console.log('.pullDownText' + catnaam + i);
                    
                    //sItem0 ook setten
                    $('.sItem'+i).css({ "height" : "27px" });
                                                   
                    $('.pullDownText' + catnaam + i).css({"width" : "143px",
                                                          "height" : "27px",
                                                          "lineHeight" : "1.2em",
                                                          "background" : "#751D1C",
                                                          "border" : "0",
                                                          "borderTop" : "1px solid #FFF",
                                                          "padding" : "0 0 0 5px",
                                                          "color" : "#FFF",
                                                          "float" : "left"                                    
                                                         });                                                                        
                                                                 
                }
            }
            
   
        }
           
                     
    }); 
 

                  
        
        
        if(window.location.href.search('photoworks') > 1) {
            getURLParam();
        }
        
        // deze functie bepaalt de hoogte van de pullDownContainer{$smarty.foreach.cats.iteration}
        function getURLParam() {    

            var sURL = window.location.href;        
            var aURLParts = sURL.split('photoworks/');    
            var aParams = aURLParts[1].split('/'); //console.log(aParams);
            
            var catArr = new Array();            
            var iMaxChars = 20;
            var teller = 0;                   
            
            for(var x=0;x<aParams.length;x++) {
                
                if(x == 1) {       
                    if(aParams[x].length > iMaxChars) { 
                        catArr[teller] = aParams[0];
                        teller++;
                    }            
                }    
                if(x == 3) {           
                    if(aParams[x].length > iMaxChars) {                
                        catArr[teller] = aParams[2];
                        teller++;
                    }            
                }    
                if(x == 5) {       
                    if(aParams[x].length > iMaxChars) {                
                        catArr[teller] = aParams[4];
                        teller++;
                    }            
                }                        
            }

                                                       
            for(var y=0;y<catArr.length;y++) {
              
                if(catArr[y] == 'year') {
                    $('#pullDownContainer1').css({"width" : "143px",
                                                  "height" : "27px",
                                                  "lineHeight" : "1.2em",
                                                  "background" : "#751D1C",
                                                  "border" : "0",
                                                 /* "borderTop" : "1px solid #FFF", */
                                                  "padding" : "0 0 0 5px",
                                                  "color" : "#FFF",
                                                  "float" : "left"                                    
                                                 });                                
                }
                if(catArr[y] == 'location') {
                    $('#pullDownContainer2').css({"width" : "143px",
                                                  "height" : "27px",
                                                  "lineHeight" : "1.2em",
                                                  "background" : "#751D1C",
                                                  "border" : "0",
                                                  /* "borderTop" : "1px solid #FFF", */
                                                  "padding" : "0 0 0 5px",
                                                  "color" : "#FFF",
                                                  "float" : "left"                                    
                                                 });                                                    

                $('.catNaam2').css({"width" : "122px",
                                    "height" : "17px",
                                    "lineHeight" : "1.2em",    /* 1.5em */
                                    "padding" : "0 0 0 0px",
                                    "float" : "left"                        
                                  });                                                                     
                }
                if(catArr[y] == 'commission') {       
                    $('#pullDownContainer3').css({"width" : "143px",
                                                  "height" : "27px",
                                                  "lineHeight" : "1.2em",
                                                  "background" : "#751D1C",
                                                  "border" : "0",
                                                  /* "borderTop" : "1px solid #FFF", */
                                                  "padding" : "0 0 0 5px",
                                                  "color" : "#FFF",
                                                  "float" : "left"                                    
                                                 });                                                    

                $('.catNaam3').css({"width" : "122px",
                                    "height" : "17px",
                                    "lineHeight" : "1.2em",    /* 1.5em */
                                    "padding" : "0 0 0 0px",
                                    "float" : "left"                        
                                  });    
                }                
            }    
            
                                  
        }          

    
    
/* END PHOTOWORKS */      
});
