/**
 * @author michael.haenel
 */


$(document).ready(function() {
    
//    if($('#cycle-1')) {
//        $('#cycle-1').cycle({ 
//            fx: 'scrollHorz',
//            prev: '#prev-1',
//            next: '#next-1',
//            timeout: 0,
//            easing: 'easeInOutCubic'
//        });
//    }
//
//    if($('#cycle-2')) {
//        $('#cycle-2').cycle({ 
//            fx: 'scrollHorz',
//            prev: '#prev-2',
//            next: '#next-2',
//            timeout: 0,
//            easing: 'easeInOutCubic'
//        });
//    }
//    
//    if($('#cycle-3')) {
//        $('#cycle-3').cycle({ 
//            fx: 'scrollHorz',
//            prev: '#prev-3',
//            next: '#next-3',
//            timeout: 0,
//            easing: 'easeInOutCubic'
//        });
//    }
    
//    if($('#cycle-4')) {
//        $('#cycle-4').cycle({ 
//            fx: 'scrollHorz',
//            prev: '#prev-4',
//            next: '#next-4',
//            timeout: 0,
//            easing: 'easeInOutCubic'
//        });
//    }
//    if($('.ngg-galleryoverview')) {
//        $('.ngg-galleryoverview').cycle({ 
//            fx: 'scrollHorz',
//            prev: '#prev-4',
//            next: '#next-4',
//            timeout: 0,
//            easing: 'easeInOutCubic'
//        });
//    }

    $('.colthis').columnize({'lastNeverTallest':true});

    
    function mycarousel_initCallback(carousel){

        jQuery('#next-4').bind('click', function() {
            carousel.next();
            return false;
        });

        jQuery('#prev-4').bind('click', function() {
            carousel.prev();
            return false;
        });
    }
    
    function mycarousel_initCallback2(carousel){

        jQuery('#next-4-2').bind('click', function() {
            carousel.next();
            return false;
        });

        jQuery('#prev-4-2').bind('click', function() {
            carousel.prev();
            return false;
        });
    }


    if($('#mycarousel')) {
        $('#mycarousel').jcarousel({
            // Configuration goes here
            scroll: 1,
            wrap: "both",
            initCallback: mycarousel_initCallback,
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
    }
    
    if($('#mycarousel2')) {
        $('#mycarousel2').jcarousel({
            // Configuration goes here
            scroll: 1,
            wrap: "both",
            initCallback: mycarousel_initCallback2,
            buttonNextHTML: null,
            buttonPrevHTML: null
        });
    }
    
    
    $('div.plus').cluetip({local:true, cursor: 'pointer', width: 430, showTitle: false, delayedClose: 1000, positionBy: 'auto', sticky:true, mouseOutClose:true, closeText:"", dropShadow:false, topOffset:160 });
    
    $( "#slider" ).slider({
        max: 510, 
        min: 40, 
        step: 10, 
        value: 100, 
        slide: function(event, ui) {
            $('.square-m input').attr('value', $(this).slider('value'));
        }
    });
    
    $('a.gallery').colorbox({rel:'gal'});
    
    VideoJS.setupAllWhenReady();
    
    $('.square-m input').attr('value', $("#slider").slider('value'));    
    $('.parallax-layer').parallax({yparallax: false});
    
    $('.date-picker').datepicker();
    
    //$('ul.sub-menu').wrap('<div class="sub-menu-wrapper" />');


    // set form select from GET-Value (type)
    $.extend({
      getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
          hash = hashes[i].split('=');
          vars.push(hash[0]);
          vars[hash[0]] = hash[1];
        }
        return vars;
      },
      getUrlVar: function(name){
        return $.getUrlVars()[name];
      }
    });

    if($.getUrlVar('type') && $('#message')) {
        $('#message option[value="'+$.getUrlVar('type')+'"]').attr('selected', 'selected');
    }
    
    if($('a.totop')){
        $('a.totop').click(function(){
            $('html, body').animate({scrollTop: '0px'}, 600);
            return false;
        });
    }
    
});

jQuery(function($){
        $.datepicker.regional['de'] = {clearText: 'l&ouml;schen', clearStatus: 'aktuelles Datum l&ouml;schen',
                closeText: 'schlie&szlig;en', closeStatus: 'ohne &Auml;nderungen schlie&szlig;en',
                prevText: '<zur&uuml;ck', prevStatus: 'letzten Monat zeigen',
                nextText: 'Vor>', nextStatus: 'n&auml;chsten Monat zeigen',
                currentText: 'heute', currentStatus: '',
                monthNames: ['Januar','Februar','M&auml;rz','April','Mai','Juni',
                'Juli','August','September','Oktober','November','Dezember'],
                monthNamesShort: ['Jan','Feb','M&auml;r','Apr','Mai','Jun',
                'Jul','Aug','Sep','Okt','Nov','Dez'],
                monthStatus: 'anderen Monat anzeigen', yearStatus: 'anderes Jahr anzeigen',
                weekHeader: 'Wo', weekStatus: 'Woche des Monats',
                dayNames: ['Sonntag','Montag','Dienstag','Mittwoch','Donnerstag','Freitag','Samstag'],
                dayNamesShort: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                dayNamesMin: ['So','Mo','Di','Mi','Do','Fr','Sa'],
                dayStatus: 'Setze DD als ersten Wochentag', dateStatus: 'W&auml;hle D, M d',
                dateFormat: 'dd.mm.yy', firstDay: 1,
                initStatus: 'W&auml;hle ein Datum', isRTL: false};
        $.datepicker.setDefaults($.datepicker.regional['de']);
});

//render gmap for locations 
 $(function(){
        $('#googleMap').gmap3(
          {action: 'init',
            options:{
              center:[51.097593,10.364399],
              zoom: 6,
              mapTypeId: google.maps.MapTypeId.TERRAIN
            }
          },
          {action: 'addMarkers',
            radius:100,
            markers: fasaList,
            clusters:{
              // This style will be used for clusters with more than 0 markers
              0: {
                content: '<div class="cluster cluster-1">CLUSTER_COUNT</div>',
                width: 53,
                height: 52
              },
              // This style will be used for clusters with more than 20 markers
              20: {
                content: '<div class="cluster cluster-2">CLUSTER_COUNT</div>',
                width: 56,
                height: 55
              },
              // This style will be used for clusters with more than 50 markers
              50: {
                content: '<div class="cluster cluster-3">CLUSTER_COUNT</div>',
                width: 66,
                height: 65
              }
            },
            marker: {
                options: {
                    clickable: true
                },
                events:{  
                    click: function(marker, event, data){
                        //console.log([marker.position]);
                        //console.log(data);
                        $('.close-overlay').live('click', function(){    
                            $('#googleMap').gmap3({
                                action:'clear', 
                                name: 'overlay'
                            });
                        });  

                          $(this).gmap3(
                            {action:'clear', name:'overlay'},
                            {action:'addOverlay',
                              latLng: marker.getPosition(),
                              content:  '<div class="info">' +
                                          '<div class="image"><img src="' + data.image + '" alt=""/></div>' +
                                          '<div class="text">' + data.description + '<div class="wrap_buttons">' + ((data.highlightLink)? '<div class="link"><a class="btn" href="'+data.highlightLink+'">'+data.highlightLinkText+'</a></div>' : '') + ((data.type)? '<div class="link"><a class="btn" href="/architektur/realisierte-projekte/energetikhaus100-'+data.type+'">'+data.typeText+'</a></div>' : '') + '<div class="link"><a class="btn" href="' + data.link + '">' + data.linkText +  '</a></div></div></div>' +
                                          '<div class="close-overlay">x</div></div>',
                              offset: {
                                x:-46,
                                y:-73
                              }
                            },
                            {   
                                action:"panTo",
                                args:[marker.position]
                            }
                          );
                    }
    //                mouseout: function(){
    //                  $(this).gmap3({action:'clear', name:'overlay'});
    //                }
              }
            }
          }
        );
      });
      

