$(document).ready(function() {
	$('#search-btn').searchHoverStatus();
	
	$('ul.nav > li').main_menu_hover();

	nr=0;
	$("#borderIMGon img").filter(function(){
		nr++;
		$(this).polaroidFrame({
				imageTopLeft:   {classes:'polaroidFrame1'},
				imageTopRight:  {classes:'polaroidFrame3'},
				imageDownRight: {classes:'polaroidFrame6'},
				imageDownLeft:  {classes:'polaroidFrame8'},
				imageLeft: 	    {classes:'polaroidFrame4'},
				imageRight:     {classes:'polaroidFrame5'},
				imageDown: 	    {classes:'polaroidFrame7'},
				imageTop: 	    {classes:'polaroidFrame2'},						
				borderSizePX:   {top:7,left:10,right:10,down:7},
				nr: nr
 		});
	})

});

/**
 * Hoverstatus for the searchform submitbutton
 */
$.fn.searchHoverStatus = function() {
	$(this).mouseover(function() {
		$(this).addClass('btn-hover');
	});
	$(this).mouseout(function() {
		$(this).removeClass('btn-hover');
	});
};

$.fn.main_menu_hover = function () {
	$(this).hover(
		function() {
			$(this).addClass('hover');
			var submenu = $(this).find('ul').eq(0);
			$(submenu).css('display','block');
		},
		function() {
			$(this).removeClass('hover');
			var submenu = $(this).find('ul').eq(0);
			$(submenu).css('display','none');
		}
	)
};


//////////////////////////////////////////
/////////&copy; Pascal Huisman////////////
//////////////////////////////////////////

jQuery.fn.polaroidFrame = function(settings) {
	var nr;
    var thisHeight =  $(this).height();
    var thisWidth =  $(this).width();
	
    var style;
    var allDivInsertBefore ;
    var allDivInsertAfter ;

    var totalWidth  = (thisWidth + settings.borderSizePX.left + settings.borderSizePX.right);
    var totalHeight = (thisHeight + settings.borderSizePX.top + settings.borderSizePX.down);
    
    if($(this).css('float')!=='none'){
    	var copyIMGstyleFloat = 'float:'+ $(this).css('float') +';';
    }else{
    	var copyIMGstyleFloat = ''//'clear:both;';
    }
    
    

    $(this).wrap('<div id="polaroid'+settings.nr+'" class="polaroidFrame"></div>');
	$('#polaroid'+settings.nr).attr('style', copyIMGstyleFloat+';width:'+totalWidth+'px;height:'+totalHeight +'px;')

	$(this).css({'float':'left','display':'block'})
    

////////TOP-LEFT
    style = 'clear:both;float:left;';
    style += 'width:'+( settings.borderSizePX.left ) +'px;';
    style += 'height:'+( settings.borderSizePX.top) +'px;';
    if(settings.imageTopLeft.url)
    	style += "background-image:url('" + settings.imageTopLeft.url + "')";
    	
    if(settings.imageTopLeft.classes)
    	var classes = ' class="'+settings.imageTopLeft.classes+'" ';
    
    allDivInsertBefore = '<div style="'+style+'" '+classes+'>&nbsp;</div>';

////////TOP
    style = 'float:left;';
    style += 'width:'+( $(this).width() ) +'px;';
    style += 'height:'+( settings.borderSizePX.top) +'px;';
    if(settings.imageTop.url)
    	style += "background-image:url('" + settings.imageTop.url + "')";
    	
    if(settings.imageTop.classes)	
        classes = ' class="'+settings.imageTop.classes+'" ';	
    allDivInsertBefore += '<div style="'+style+'" '+classes+'>&nbsp;</div>';


////////TOP-RIGHT
    style = 'float:left;';
    style += 'width:'+( settings.borderSizePX.right ) +'px;';
    style += 'height:'+( settings.borderSizePX.top) +'px;';
    if(settings.imageTopRight.url)
    	style += "background-image:url('" + settings.imageTopRight.url + "')";
    	
    if(settings.imageTopRight.classes)	
    	classes = ' class="'+settings.imageTopRight.classes+'" ';
    allDivInsertBefore += '<div style="'+style+'" '+classes+'>&nbsp;</div>';

////////LEFT
    style = 'clear:both;float:left;';
    style += 'width:'+(settings.borderSizePX.left) +'px;';
    style += 'height:'+( thisHeight ) +'px;';
    if(settings.imageLeft.url)
    	style += "background-image:url('" + settings.imageLeft.url + "')";
    	
    if(settings.imageLeft.classes)	
    	classes = ' class="'+settings.imageLeft.classes+'" ';
    allDivInsertBefore += '<div style="'+style+'" '+classes+'>&nbsp;</div>';

   $(allDivInsertBefore).insertBefore(this);


////////RIGHT
    style = 'float:left;';
    style += 'width:'+(settings.borderSizePX.right) +'px;';
    style += 'height:'+( thisHeight ) +'px;';
    if(settings.imageRight.url)
    	style += "background-image:url('" + settings.imageRight.url + "')";
    	
    if(settings.imageRight.classes)	
    	classes = ' class="'+settings.imageRight.classes+'" ';
    allDivInsertAfter = '<div style="'+style+'" '+classes+'>&nbsp;</div>';


////////DOWN-LEFT
    style = 'clear:both;float:left;';
    style += 'width:' + ( settings.borderSizePX.left ) + 'px;';
    style += 'height:'+( settings.borderSizePX.down) +'px;';
    if(settings.imageDownLeft.url)
    	style += "background-image:url('" + settings.imageDownLeft.url + "')";
    	
    if(settings.imageDownLeft.classes)	
    	classes = ' class="'+settings.imageDownLeft.classes+'" ';
    allDivInsertAfter += '<div style="'+style+'" '+classes+'>&nbsp;</div>';

////////DOWN
    style = 'float:left;';
    style += 'width:'+(thisWidth) +'px;';
    style += 'height:'+( settings.borderSizePX.down) +'px;';
    if(settings.imageDown.url)
    	style += "background-image:url('" + settings.imageDown.url + "')";
    	
    if(settings.imageDown.classes)	
    	classes = ' class="'+settings.imageDown.classes+'" ';
    allDivInsertAfter += '<div style="'+style+'" '+classes+'>&nbsp;</div>';
	
////////DOWN-RIGHT
    style = 'float:left;';
    style += 'width:' + ( settings.borderSizePX.right ) + 'px;';
    style += 'height:'+( settings.borderSizePX.down) +'px;';
	if(settings.imageDownRight.url)
    	style += "background-image:url('" + settings.imageDownRight.url + "')";
    	
    if(settings.imageDownRight.classes)	
    	classes = ' class="'+settings.imageDownRight.classes+'" ';
    allDivInsertAfter += '<div style="'+style+'" '+classes+'>&nbsp;</div>';

    allDivInsertAfter+='<div style="clear:both;"></div>'; 
    $(allDivInsertAfter).insertAfter(this);
};
