function moveButtoncontainer()
{
	jQuery('.addreactionblock .formholder, .mailafriendblock .formholder').each(
		function()
		{
			var t = this;
			var buttonContainer = jQuery('.button-container', t);
			
			jQuery(t).after(buttonContainer);
		}
	);
}

function makeButton()
{
	jQuery('.searchresultsblock .pages .previous, .searchresultsblock .pages .next, .jobreactionblock a, .button-container input, .button-container a, .buttons input, .quickorder input, .checkout a, .button-container ul li a, .categorybutton, .mailafriendblock a, .mailagentblock a, .clearbasket a, .basketaddblock a, .objectbasketblock .remove a, .button-container .button, .rssbuttonholder a').each(function()
	{
		var button = this;
		if(button.type != 'hidden') 
		{
		    jQuery(button).wrap('<span class="candywrapper"></span>');
		} else {
			jQuery(button).css('display','none');
		}
	});
}

function changeForm()
{
	jQuery('.surveycontainer .q_multipleresponse').each(
		function() 
		{
			var t = this;
			var newDiv = jQuery('<div class="checkboxes">');
			var spanText = jQuery('.question-text',t);
			var getTables = jQuery('table',t);
			var getSelect = jQuery('select',t);
			var breakIt  = jQuery('br',t);             
			var element = new Array;
			var type = new Array;
			var aantalChilds;
			
			if ((getTables.length+getSelect.length)==0)
			{
				breakIt.remove();
				aantalChilds = t.childNodes.length;
				
				for (var x = 0; x<aantalChilds;x++)
				{
					if (t.childNodes[x].tagName=='INPUT')
					{    
						element[x] = t.childNodes[x];
						type[x] = t.childNodes[x].tagName;
					}
					
					if (t.childNodes[x].tagName=="LABEL")
					{
						element[x] = t.childNodes[x];
						type[x] = t.childNodes[x].tagName;
					}
				}
				
				for (var x = 0; x<aantalChilds;x++)
				{
					if(element[x] =='object');                        
					{
						newDiv.append(element[x]);
					}
					if(type[x] == 'LABEL')
					{
						newDiv.append(jQuery('<br>'));
					}
				}
					
				spanText.after(newDiv);
			}
		}
	);
}

function changeFormButton()
{
    jQuery('.surveycontainer').each( function() 
	{
        var t=this;
        var formQuestions = jQuery('.surveyquestion',t);
        if (formQuestions.length==0) 
		{
            var plainText = jQuery('.plain-text', t);
            if(plainText)
            {
                jQuery('.button-container', t).addClass("firstbox");
            }
        }
    });
}

/** Customer Specific **/
function imageReplace()
{
    Cufon.replace('#bannerimage .articlelistblock .info h3 a');
    Cufon.replace('ol li h6', {fontFamily: 'Futura Lt'});	
    
	jQuery('#contenttop h2').imageReplace({font: 'Century Gothic', maxwidth: '230px'});
	jQuery('#contenttop h3').imageReplace({font: 'Futura Lt', fontweight:'regular', maxwidth: '230px'});
	
	jQuery('#rotateblocks h2').not(jQuery('#contentbottom h2')).imageReplace({font: 'Century Gothic', maxwidth: '160px'});
	jQuery('#rotateblocks h3').imageReplace({font: 'Futura Lt', fontweight:'regular', maxwidth: '160px'});
	
	makeTitleheader();
}

function makeTitleheader() {
    jQuery('.block-output').not(jQuery('.tabnavigationblock, .blogholderblock, #bannerimage .articlelistblock')).each(function() {

        var block = this;

        jQuery('h2, h3, h4, h5', block).each(function() {
            var header = this;
            if(jQuery('.cufon', header).length>0) {
                jQuery(header).addClass('cufonheader');
            }
        });
        
        var newInBlock = jQuery('<div class="titleheader">');        
        var InBlockHeaders = jQuery('div h2.imagereplaced, div h3.imagereplaced, div h2.cufonheader, div h3.cufonheader, div h4.cufonheader, div h5.cufonheader',block);
        
        if(InBlockHeaders.length>0) {
            for(var x=0;x<InBlockHeaders.length;x++) {
                if(x==0) {
                    jQuery(InBlockHeaders[x]).before(newInBlock);
                }
                newInBlock.append(jQuery(InBlockHeaders[x]));
            }        
        }        

        var newBlock = jQuery('<div class="titleheader">');                
        var headers = jQuery('h2.imagereplaced, h3.imagereplaced, h2.cufonheader, h3.cufonheader, h4.cufonheader, h5.cufonheader',block).not(jQuery('div .imagereplaced, div .cufonheader',block));
        
        if(headers.length>0) {
            for(var x=0;x<headers.length;x++) {
                if(x==0) {
                    jQuery(headers[x]).before(newBlock);
                }
                newBlock.append(jQuery(headers[x]));
            }
        }
    });	
}

function createHover() {
    jQuery('.linklistblock input, .linkblock input, .surveycontainer .button-container input').mouseover(function() { jQuery(this).addClass('hover');}).mouseout(function() { jQuery(this).removeClass('hover');});
    jQuery('.epaper .searchresultsblock ul li').mouseover(function() { jQuery(this).addClass('hover');}).mouseout(function() { jQuery(this).removeClass('hover');});
    jQuery('.linklistblock input').each(function() {
        var t = this;
        jQuery(t.parentNode).mouseover(function() { jQuery(this).addClass('lihover');}).mouseout(function() { jQuery(this).removeClass('lihover');});
    });
    jQuery('#contenttop .block-output, #rotateblocks .block-output').mouseover(function() { 
	        jQuery('.plain-text h2 img', this)[0].src = jQuery('.plain-text h2 img', this)[0].src.replace(/2684BF/i,'FF7C08');
	        jQuery('.plain-text h3 img', this)[0].src = jQuery('.plain-text h3 img', this)[0].src.replace(/2684BF/i,'FF7C08');
        }).mouseout(function() { 
	        jQuery('.plain-text h2 img', this)[0].src = jQuery('.plain-text h2 img', this)[0].src.replace(/FF7C08/i,'2684BF');
	        jQuery('.plain-text h3 img', this)[0].src = jQuery('.plain-text h3 img', this)[0].src.replace(/FF7C08/i,'2684BF');
        }
    );      
    jQuery('#rotateblocks .block-output').click(function() { 
			jQuery('#rotateblocks h2 img, #rotateblocks h3 img').each(function() {
				var header = this;
				header.src = header.src.replace(/FF7C07/i,'2684BF');
				header.src = header.src.replace(/FF7C07/i,'2684BF');
			});
	        jQuery('.plain-text h2 img', this)[0].src = jQuery('.plain-text h2 img', this)[0].src.replace(/FF7C08/i,'FF7C07');
	        jQuery('.plain-text h3 img', this)[0].src = jQuery('.plain-text h3 img', this)[0].src.replace(/FF7C08/i,'FF7C07');
        }
    );  
}

function makeDropDownList() {
    jQuery('#headerlist .linklistblock ul').each(function() {
        var list = this;
        if(jQuery('.linkbutton', list).length>0) {
            var newListItem = jQuery('<ul>');
            var newItem = jQuery('<li class="selectlist">');
            var pageTitle = document.title;
            var label = jQuery('<label>' + jQuery('.linkbutton')[0].innerHTML + '</label>');
            jQuery(list).wrap(newListItem);
            jQuery(list).wrap(newItem);
            jQuery(list).before(label);
        }
    });
    
    jQuery('.selectlist').click(function() { 
        if(this.className.indexOf('hover')<0) {
            jQuery('.selectlist ul li').removeClass('lihover');
            jQuery(this).addClass('hover');
            jQuery('.selectlist ul').css('display','block');
        } else {
            jQuery(this).removeClass('hover');
            jQuery('.selectlist ul').css('display','none');
        }
    });
    
    jQuery('.selectlist ul li').mouseover(function() {
        jQuery('.selectlist ul li').removeClass('lihover');
        jQuery(this).addClass('lihover');
    });
}


function makeOrderedList() {
    jQuery('ol').each( function() {
        var list = this;
        var counter = 1;
        jQuery('li',list).each(function() {
            var liElement = this;
            
            liElement.innerHTML = "<h6>" + counter + "</h6>" + liElement.innerHTML;
            counter++;
        });
    });
}

function setCorrectListItem() {
    jQuery('.displayarticleblock ul li, .blogitem ul li').each(function() {
        var liElement = this;
        if(jQuery('a',liElement).length>0) {
            jQuery(liElement).addClass('anchor');
        }
    });
    
    jQuery('.linklistblock ul li').each(function() {
        var liElement = this;
        if(jQuery('input',liElement).length>0) {
            jQuery(liElement).addClass('button');
        }    
    });
}

function changeImageFilelist() {
	jQuery('.filelistblock ul li a').not(jQuery('#mc_bestanden .filelistblock ul li a')).each(function() {
        var anchor = this;
        var extension = anchor.innerHTML.substring(anchor.innerHTML.length-3,anchor.innerHTML.length);
        if(extension!=""){
            jQuery(anchor).addClass(extension)    
        }
    });
}   

function changeGallery() {
    var counter = 0;
    jQuery('.gallerycontrol ul li').each(function() {
        var liElement = this;
        counter++;
        if(jQuery('a',liElement).length==0) {
            jQuery(liElement).addClass('hide').addClass('hide_' + counter);
        }
    });
}

/*** functies voor de schema's ***/
function hover(shape, selected) {
    if(selected==false) {
        changeImage.src = "/themes/themes.clixmaster/images/schema/" +  shape + "_hover.gif";
    } else {
        changeImage.src = "/themes/themes.clixmaster/images/schema/" +  shape + "_selected.gif";
    }
}

function hoverOut() {
    changeImage.src=oldSrc;
}
/*********************************/

function changeJobs() {
    if(jQuery('.jobreactionblock a').length >0) {
        jQuery('.jobreactionblock').addClass('jobreactionlink');
        jQuery('.jobreactionblock').mouseover(function() { jQuery(this).addClass('jobreactionblockhover');}).mouseout(function() { jQuery(this).removeClass('jobreactionblockhover');});;
    }

    var firstItem = jQuery('.joblistblock ul li:eq(0)');
    jQuery(firstItem).addClass('fc').mouseover(function() { jQuery(this).addClass('fchover');}).mouseout(function() { jQuery(this).removeClass('fchover');});;
    jQuery('.joblistblock ul li').mouseover(function() { jQuery(this).addClass('hover');}).mouseout(function() { jQuery(this).removeClass('hover');});

    var aantal = jQuery('p',firstItem).length;
    var aantalLink = jQuery('p.joblist_link',firstItem).length;
    var width = 100 - ((aantal-aantalLink) * 20);
    jQuery('.joblistblock ul li h3').css('width', width + '%'); 
}

function grayIcons() {
    if(jQuery('.htmlblock .icons li').length>0) {
        jQuery('.linklistblock ul li a').each(function() {
            var anchor = this;
            var text = parseInt(FindIcon(anchor.innerHTML));
            if(text>0) {
                jQuery(anchor).css('background','url("/' + text + '") left 2px no-repeat').css('padding-left','20px');
            }
        });
    }
}

function FindIcon(thumbName) {
    return iconList[thumbName];
}

var iconList = {};
function buildIconList() {
	jQuery('.htmlblock .icons li').each(function(){
	
		var self = this;
	
		var name = jQuery('.value',self)[0].innerHTML;
		var icon = jQuery('.image',self)[0].innerHTML;
		
		iconList[name] = icon;
	});
}

jQuery(function(){

    jQuery("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'fast', /* fast/slow/normal */
		padding: 40, /* padding for each side of the picture */
		opacity: 0.5, /* Value betwee 0 and 1 */
		showTitle: false, /* true/false */
		allowresize: false, /* true/false */
		counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
		theme: 'light_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
		callback: function(){}
	});
	//makeButton();
	makeOrderedList();
	moveButtoncontainer();
	changeForm();
	changeFormButton();
	createHover();
	makeDropDownList();
	setCorrectListItem();
	changeImageFilelist();
	changeGallery();
	changeJobs();
	imageReplace();
	buildIconList();
	grayIcons();
});