﻿
//var msToFtr = new Array({msId:'4',feature:$('#ftr_5')});
//var msToProd = new Array({msId:'2',product:$('#prod_7f56ff71-b385-41ca-9a04-aa194e95949c')});
//var prodToFtr = new Array({prodId:'e10258ab-600a-4de0-ad2e-4cc18c39e9ff',feature:$('#ftr_6')},{prodId:'7f56ff71-b385-41ca-9a04-aa194e95949c',feature:$('#ftr_5')});  
//var imagesToPreload = new Array('/lib/images/afbeelding_tr.jpg');

$(document).ready(function() {
	
	if (!($('body.portal').length)) initIndexMotion();


    $.fn.nyroModal.settings.regexImg = '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$|image.aspx';
});      



function initIndexMotion()
{
	$('.PanelHTML').hide();
	var x = '<div id="toppanel"><div id="panel"><div id="panel_contents"></div></div><div class="panel_button" style="display: block;"><a href="#">' + panelOpenText + '</a></div><div class="panel_button" id="hide_button" style="display: none;"><a href="#">' + panelCloseText + '</a></div></div>'
	$('.container_wrapper').prepend(x);
	$('#panel_contents').html($('.PanelHTML').html());
	
	$("div.panel_button").click(function(){
		$('#utils').hide('fast');
		$("div#panel").animate({
			height: "146px"
		}, "slow", function(){
			$('#utils').css('z-index','0');
		});
		$("div.panel_button").toggle();
	});	
	
   $("div#hide_button").click(function(){
		$("div#panel").animate({
			height: "0px"
		}, "slow", function(){
			$('#utils').css('z-index','2');
			$('#utils').show('fast');
		});
	});	
}


function highlightMarktSegment(msId)
{
    try
    {
        //  oude highlights opruimen
        //
        $('.ftrhighlight').removeClass('ftrhighlight');
       
    
        //  highlight products
        //        
        if (msToProd && msToProd.length > 0)
        {
            
            for (i = 0; i < msToProd.length; i++) 
            { 
		        if (msToProd[i].msId == msId && msToProd[i].product.length > 0)
		        {
		            msToProd[i].product.addClass('ftrhighlight');
		        }
	        }
	        
        }
        
        //  highlight features
        //
        if (msToFtr && msToFtr.length > 0)
        {
            
            for (i = 0; i < msToFtr.length; i++) 
            { 
		        if (msToFtr[i].msId == msId && msToFtr[i].feature.length > 0)
		        {
		            msToFtr[i].feature.addClass('ftrhighlight');
		        }
	        }
	        
        }
        //  highlight marktsegment button
        //
        $('.marktsegmentHighlight').removeClass('marktsegmentHighlight');
        $('#ms_'+ msId).addClass('marktsegmentHighlight');
    }
    catch(Error)
    {
        //alert(Error.message);
    }
}
function unhighlight()
{
    //  oude bullets opruimen
    //
    $('.ftrbullet').removeClass('ftrbullet');
}
function highlightProduct(productId,productImage)
{
    try
    {
        unhighlight();
    
        //  bullet features
        //
        if (prodToFtr && prodToFtr.length > 0)
        {
            for (i = 0; i < prodToFtr.length; i++) 
            { 
		        if (prodToFtr[i].prodId == productId && prodToFtr[i].feature.length > 0)
		        {
					//$('body').prepend('<div style="padding:10px;border:4px solid red;">' + prodToFtr[i].feature + '</div>');
		            
		            prodToFtr[i].feature.parent('li').addClass('ftrbullet');
		        }
	        }	        
        }
        
        //  toon image
        //
        $('.productimg').attr('src',productImage);
    }
    catch(Error)
    {
        //alert(Error.message);
    }    
}
function highlightFeature(ftrId,ftrImage)
{
    try
    {
        unhighlight();
    
        //  bullet features
        //
        if (ftrToProd && ftrToProd.length > 0)
        {
            
            for (i = 0; i < ftrToProd.length; i++) 
            { 
		        if (ftrToProd[i].featureId == ftrId && ftrToProd[i].product.length > 0)
		        {
		            ftrToProd[i].product.parent().addClass('ftrbullet');
		        }
	        }
	        
        }
        
        //  toon image
        //
        $('.productimg').attr('src',ftrImage);
    }
    catch(Error)
    {
        alert(Error.message);
    }    
}
var preloadDummy;
function preloadImages(stringArray)
{
    preloadDummy = new Array();

    try
    {
        for (i = 0; i < stringArray.length; i++) { 
		    preloadDummy[i] = new Image()
		    preloadDummy[i].src = stringArray[i]
	    }
    }
    catch(Error)
    {
        //alert(Error.message);
    }
}

function carousselShow(imagename,element)
{
    
    var img = $('#carousselimg');
    var oldimg = $('#oldimage');
    var elem = $(element);
    
    //  stop running animations
    //
    $('#carousselimg:animated').stop();
    $('#oldimage:animated').stop();
    
    //  highlight menuitem
    //
    $('.carousselHighlight').removeClass('carousselHighlight');
    elem.addClass('carousselHighlight');
    
    if (img.length > 0)
    {      
        try
        {             
            
            if (oldimg.length == 0)
            {
                oldimg = img.clone();
                img.css('z-index','10');
                oldimg.css('z-index','9');                 
                
                img.parent().append('<img id="oldimage" src="" />');
                oldimg = $('#oldimage');
                
                // css stuff
                
                img.parent().css('position','relative');
                img.parent().css('height','184px');
                img.parent().css('overflow','hidden');
                
                img.css('position','absolute');
                oldimg.css('position','absolute');     
            }
            
            img.attr('id','oldimage');            
            oldimg.attr('id','carousselimg');  

            oldimg.attr('src',imagename);

            oldimg.fadeTo(2000 , 1.0);
            img.fadeTo(2000, 0.0);   
            
            //  trigger automatic slide
            //
            clearTimeout(slideTimeout);
            slideTimeout = setTimeout("slideCaroussel()",5000);   
        }
        catch(err)
        {
            alert(err.message);
        }
    }    
}

var lastIndex = 0;
var slideTimeout;
function slideCaroussel()
{
    try
    {
        var hyperlinks = $('.menucaroussel ul li a');
        
        if (hyperlinks.length == 0)
            return;
        
        var hyperlink = $(hyperlinks[lastIndex])        
        lastIndex = lastIndex + 1;       
        
        if (lastIndex > hyperlinks.length-1)
            lastIndex = 0;
        
        carousselShow(hyperlink.attr('rel'),hyperlink);    
    }
    catch(err)
    {
        alert(err.message);
    }
}

function OpenPics(url, iwidth, iheight) {
    window.open(url, "afbeelding", "width=" + iwidth + ",height=" + iheight + ",left=125,top=100");
}


