$(document).ready(function() {

	if (typeof(HeijmansFontReplacementEnabled) != 'undefined' && HeijmansFontReplacementEnabled == true) {
		initFlir();
	}

	layout.init();
	menu.init();
	projectOverzichtThumbsHandling();
	initPhotobanner();
	
	//add .hovers to element
    $('.lister_hover_tag li').hover(function() { // IE6 does not support :hover on elements other than <a>
        $(this).addClass('hover');
    }, function() {
        $(this).removeClass('hover');
    });
	
});

function log() {
  if (window && window.console && window.console.log)
    for(var i=0, len = arguments.length; i < len; i++)
      console.log(arguments[i]);
}

function initFlir() {

	//check browser is safari or chrome, if true, disable flir
	var ua = navigator.userAgent.toLowerCase();
	
	if (ua.indexOf('chrome')  > -1){
		var is_chrome = true;
		//alert("chrome");
	}
	if ($.browser.safari) {
		var is_safari = true;
		//alert("safari");
	}
	
	if (is_chrome){		
		
	}
	else if (is_safari){	
		
	}
	else {	
		//BEGIN script activate flir
		if (typeof(FLIR)!='undefined') {
			FLIR.init( { path: '/heijmans_shared/js/lib/facelift-2.0b3-B/' } );
	
			/*
				Beschikbare fonts:
	
				heijmans-blackcon
				heijmans-boldcon
				heijmans-boldconitalic
				heijmans-light
				heijmans-normal
				heijmans-normalitalic
	
			*/
			
			$('div.main_content h1').each(function() {    //zie de custom_header voor de instellingen
				FLIR.replace(this, new FLIRStyle({ cFont: FLIR_H1_FONT, mode: 'wrap'}));
				$(this).css('visibility', 'visible');
			});
	
			$('h3').each(function() {     //zie de custom_header voor de instellingen
				FLIR.replace(this, new FLIRStyle({ cFont: FLIR_H3_FONT, mode: 'wrap'}));
			});
			
				
			/*//backup
			$('div.main_content h1').each(function() {    //zie de custom_header voor de instellingen
				FLIR.replace(this, new FLIRStyle({ cFont: FLIR_H1_FONT, mode: 'wrap'}));
			});
	
			$('h3').each(function() {     //zie de custom_header voor de instellingen
				FLIR.replace(this, new FLIRStyle({ cFont: FLIR_H3_FONT, mode: 'wrap'}));
			});*/
		}
		//END script activate flir		
	}	
}

function initPhotobanner() {

	if (!$('#supersize')) {
		return;
	}


	
	if ($('body').hasClass('page_home')) {
		var supersize_height = 354;
	} else {
		var supersize_height = 196;
	}
	
	if (typeof(PhotoHeaderSlideInterval)=='undefined') {
		PhotoHeaderSlideInterval = 5000;
	}

	$.fn.supersized.options = {  
		startwidth: 1300,
		startheight: supersize_height,
		vertical_center: 1,
		slideshow: 1,
		transition: 1,
		slide_interval: PhotoHeaderSlideInterval
	};
    $('#supersize').supersized();
}


/****************************
 * Menu
 ***************************/


var menu = {
	init: function() {
		$('.main_menu_container ul li:not(.main_menu_container ul ul li)').hover(function(){		
			$(this).addClass('hover');
		},function() {			
			$(this).removeClass('hover');
		});
	}
}

var layout = {
	init: function() {
		layout.breadcrumbAutoSizing();
		
		$(window).resize(function() {
			layout.breadcrumbAutoSizing();
		});
		
		layout.breadcrumbTransparancy();
	},
	
	breadcrumbTransparancy: function(){
		$('div.breadcrumbs').fadeTo(10, 0.8);
		$('#breadcrumbs-fill').fadeTo(10, 0.8);
	},
	
	breadcrumbAutoSizing: function() {

		breadcrumbs_fill_width = $(window).width() - 914;
		
		if (breadcrumbs_fill_width % 2 == 0) {
			breadcrumbs_fill_width = breadcrumbs_fill_width / 2;
		} else {
			breadcrumbs_fill_width = (breadcrumbs_fill_width-1) / 2 + 1;
		}

		$('#breadcrumbs-fill').css('width',breadcrumbs_fill_width);
	}
}





/* projecten detail, thumb box navigatie */
// !horizontal movement
// every size - height or width, must be even

function projectOverzichtThumbsHandling() {   
    /* PROJECT OVERZICHT SLIDE - INIT */
    var C_rijen_aantal = 3;
    var C_items_per_rij_aantal = 1;     
    
	// !does not work propely, put the mask hide on the following line
    //var C_mask_hoogte = $('.view_detail .thumbs_box .mask').height();  
	var C_mask_hoogte = 332;   //mask.height
    var C_li_hoogte = 108;     //li.width + margin
    
    //get li.length
    var C_li_aantal = $('.view_detail .thumbs_box .mask li').length;   
    
    //math ul.width
    var C_new_ul_lengte = Math.ceil(C_li_aantal/C_rijen_aantal)*C_li_hoogte;
    
    //math paging items per page
    C_item_aantal_per_pagina = C_rijen_aantal * C_items_per_rij_aantal;
    var C_pagina_aantal = Math.ceil(C_li_aantal/C_item_aantal_per_pagina);
    
    // set ul.width
    $('.view_detail .thumbs_box .mask ul').css({
        'width' : C_new_ul_lengte        
     });
    
    /* PROJECT OVERZICHT SLIDE - MOVE! */   
    var C_current_page = 1;     
    var C_current_position;
    var C_new_position;     
    var animating = false;
    
	
    if (C_li_aantal < (C_item_aantal_per_pagina+1)) {
        $(".view_detail .thumbs_box .btn_volgende").fadeOut(750);
    }
	
    
    //buttons - init    
    if ( C_current_page < 2){
        $(".view_detail .thumbs_box .btn_vorige").fadeOut(500);   
        
        $(".view_detail .thumbs_box .btn_volgende").click(function(){
            if (animating) {
                return;
            }
            var p = $(".view_detail .thumbs_box .mask ul");
            var position = p.position();
            
            C_current_position = position.top;
            if (jQuery.browser.msie6 = jQuery.browser.msie  && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) ) {      //ONLY IE6
		        C_new_position = C_current_position - (C_mask_hoogte + 1);    //margin-top or _top compensation
		    }
		    else {				
		        C_new_position = C_current_position - (C_mask_hoogte - 8);
		    }
            
            //hide - show button            
            C_current_page = C_current_page + 1;
            
            if (C_current_page == C_pagina_aantal) {
                $(this).fadeOut(500);
            }
            if (C_current_page > 1) {
                $(".view_detail .thumbs_box .btn_vorige").fadeIn(750);
            }
            
            animating = true;
            
            //animate
            $(".view_detail .thumbs_box .mask ul").animate({
                top: C_new_position + "px"
            }, 1500, function(){
                animating = false;
            });
        });
    }   
    
    if ( C_current_page < (C_pagina_aantal+1)){     
        
        $(".view_detail .thumbs_box .btn_vorige").click(function(){ 
            if (animating) {
                return;
            }   
            var p = $(".view_detail .thumbs_box .mask ul");
            var position = p.position();
            
            C_current_position = position.top;           
             if (jQuery.browser.msie6 = jQuery.browser.msie  && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent) ) {      //ONLY IE6
                 C_new_position = C_current_position+(C_mask_hoogte + 1);    //margin-top or _top compensation
            }
            else {
                 C_new_position = C_current_position+(C_mask_hoogte - 8);
            }
			                
            //hide - show button
            C_current_page = C_current_page-1;  
            
            if ( C_current_page == 1){
                $(this).fadeOut(500);           
            }       
            $(".view_detail .thumbs_box .btn_volgende").fadeIn(750);
            
            animating = true;
            
            //animate
            $(".view_detail .thumbs_box .mask ul").animate({ 
                top: C_new_position+"px"           
            }, 1500, function() { animating = false; } );
        });
    } 
}

function showImage(img) {
    document.getElementById('imgGroot').src = img;
}   