jQuery(document).ready(function($){
//-------------------MEGAMENUE-----------------------	
//---Main Nav js to avoid hiding navi when focused in a input---
	$('#menuitem_kontakt .menu_box input').focus(function() {
		$('#menuitem_kontakt .menu_box').addClass('menu_box_focus');
		$('#menuitem_kontakt .menuitem_bg').addClass('menuitem_bg_focus');
	});
		
	$('#menuitem_kontakt .menu_box input').focusout(function() {
		$('#menuitem_kontakt .menu_box').removeClass('menu_box_focus');
		$('#menuitem_kontakt .menuitem_bg').removeClass('menuitem_bg_focus');
	});
	
	$('#menuitem_suche .menu_box input').focus(function() {
		$('#menuitem_suche .menu_box').addClass('menu_box_focus');
		$('#menuitem_suche .menuitem_bg').addClass('menuitem_bg_focus');
	});
	$('#menuitem_suche .menu_box input').focusout(function() {
		$('#menuitem_suche .menu_box').removeClass('menu_box_focus');
		$('#menuitem_suche .menuitem_bg').removeClass('menuitem_bg_focus');
	});
	
	$('#menuitem_login .menu_box input').focus(function() {
		$('#menuitem_login .menu_box').addClass('menu_box_focus');
		$('#menuitem_login .menuitem_bg').addClass('menuitem_bg_focus');
	});
	$('#menuitem_login .menu_box input').focusout(function() {
		$('#menuitem_login .menu_box').removeClass('menu_box_focus');
		$('#menuitem_login .menuitem_bg').removeClass('menuitem_bg_focus');
	});

//----------------------SOCIALBOOKMARKS--------------------------
//---Add hover effect to inputs of type image---
    $('input[type="image"], .tx-spsocialbookmarks-pi1 img').hover(
        function() {
            // Get src of tag; tagSrc is stored globally to be replaced
            tagsSrc = $(this).attr('src');
            // Extract filename, extension and append _hover to filename
            var url = tagsSrc.replace(/\.png|\.gif|\.jpg|\.jepg/, '_hover');
            var ext = tagsSrc.match(/(\.png|\.gif|\.jpg|\.jepg)$/g);
            // change src
            $(this).attr({
                src: (url+ext[0])
            })   
        },
        function() {
            // change src
            $(this).attr({
                src: (tagsSrc)
            })
        }
    );
$('.tx-spsocialbookmarks-pi1 img').click(
        function() {
            // Get src of tag; tagSrc is stored globally to be replaced
            tagsSrc = $(this).attr('src');
            // Extract filename, extension and append _hover to filename
            var url = tagsSrc.replace('_hover', '');
            // change src
            $(this).attr({
                src: (url)
            })
        },
        function() {
            // change src
            $(this).attr({
                src: (tagsSrc)
        })
        }
    );

//---Add hover effect to inputs of type image--- "more-button" "offer-button
   $('img[src*="button_clean_grey_more"],img[src*="button_clean_grey_offer"]').hover(
        function(){
             // Get src of tag; tagSrc is stored globally to be replaced
                tagsSrc = $(this).attr('src');
                // Extract filename, extension and append _hover to filename
                var url = tagsSrc.replace(/\uploads\/pics/, 'fileadmin/templates/layouts/itplusx.de/images/buttons');
                var newurl = url.replace(/_[0-9]+\.png|_[0-9]+\.gif|_[0-9]+\.jpg|_[0-9]+\.jepg|\.png|\.gif|\.jpg|\.jepg/, '_hover');
                var ext = tagsSrc.match(/(\.png|\.gif|\.jpg|\.jepg)$/g);
                
                // change src
                $(this).attr({
                    src: (newurl+ext[0])
                })
        },
        function(){
            // change src
                $(this).attr({
                    src: (tagsSrc)
               })
        });


    $('#menuitem_unternehmen .csc-textpic-imagewrap img, #extended .csc-textpic-imagewrap img').hover(
        function(){
             // Get src of tag; tagSrc is stored globally to be replaced
                tagsSrc = $(this).attr('src');
                // Extract filename, extension and append _hover to filename
                var url = tagsSrc.replace(/\uploads\/pics/, 'fileadmin/templates/layouts/itplusx.de/images/logos');
                var newurl = url.replace(/_[0-9]+\.png|_[0-9]+\.gif|_[0-9]+\.jpg|_[0-9]+\.jepg|\.png|\.gif|\.jpg|\.jepg/, '_hover');
                var ext = tagsSrc.match(/(\.png|\.gif|\.jpg|\.jepg)$/g);

                // change src
                $(this).attr({
                    src: (newurl+ext[0])
                })
        },
        function(){
            // change src
                $(this).attr({
                    src: (tagsSrc)
               })
        });

        $('#menuitem_unternehmen .csc-textpic-imagewrap img, #extended .csc-textpic-imagewrap img').click(
        function(){
             // Get src of tag; tagSrc is stored globally to be replaced
                tagsSrc = $(this).attr('src');
                // Extract filename, extension and append _hover to filename
                var url = tagsSrc.replace(/\uploads\/pics/, 'fileadmin/templates/layouts/itplusx.de/images/logos');
                var newurl = url.replace( '_hover', '');

                // change src
                $(this).attr({
                    src: (newurl)
                })
        },
        function(){
            // change src
                $(this).attr({
                    src: (tagsSrc)
               })
        });
		
		$('.indent .external-link-new-window img').hover(
			function(){
				$(this).attr('src','fileadmin/templates/layouts/itplusx.de/images/buttons/button_clean_grey_order_hover.png');	
			},
			function(){
				$(this).attr('src','fileadmin/templates/layouts/itplusx.de/images/buttons/button_clean_grey_order.png');
			}
		);
		

//------------------------------FILEUPLOAD-'filestyle'--------------------------------------------	
//Initialize filestyle plugin

	$("input[type=file]").filestyle({ 
	     image: "/fileadmin/templates/layouts/itplusx.de/images/buttons/choose-file.png",
	     imageheight : 25,
	     imagewidth : 25,
	     width : 170
	});
	
//-----------------------------RECALL-FORM-------------------------------------	
//---Reset Recall-form on '#menuitem_kontakt.mouseleave'---
	$('#menuitem_kontakt').mouseleave(function() {
		
		if ($(this).find('.menuitem_bg').hasClass('menuitem_bg_focus')) {
		} else {
			$('#menuitem_kontakt input').each(function(index){				
				powermail_validator.data('validator').reset($(this));
			});
		}
	});	
//------------------------- PICTURE PRELOAD ------------------------
//--- Write all background src's in #nav to srcarray ---	
	
	srcArray = new Array();
	srcArray[0] = '/fileadmin/templates/layouts/itplusx.de/images/header/top_nav_separator.png';
	srcArray[1] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_suche_top.png';
	srcArray[2] = '/fileadmin/templates/layouts/itplusx.de/images/header/login_hover.png';
	srcArray[3] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_br.png';
	srcArray[4] = '/fileadmin/templates/layouts/itplusx.de/images/header/suche_hover.png';
	srcArray[5] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_right.png';
	srcArray[6] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_bottom.png';
	srcArray[7] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_bl.png';
	srcArray[8] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_unternehmen_top.png';
	srcArray[9] = '/fileadmin/templates/layouts/itplusx.de/images/header/referenzen_hover.png';
	srcArray[10] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_left.png';
	srcArray[11] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_referenzen_top.png';
	srcArray[12] = '/fileadmin/templates/layouts/itplusx.de/images/menu/menu_small_left_color.png';
	srcArray[13] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_leistungen_top.png';
	srcArray[14] = '/fileadmin/templates/layouts/itplusx.de/images/header/kontakt_hover.png';
	srcArray[15] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_tr.png';
	srcArray[16] = '/fileadmin/templates/layouts/itplusx.de/images/header/leistungen_hover.png';
	srcArray[17] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_login_top.png';
	srcArray[18] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_tl.png';
	srcArray[19] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_top.png';
	srcArray[20] = '/fileadmin/templates/layouts/itplusx.de/images/header/unternehmen_hover.png';
	srcArray[21] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_box_bg.png';
	srcArray[22] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_kontakt_top.png';	
	srcArray[23] = '/fileadmin/templates/layouts/itplusx.de/images/buttons/button_clean_grey_login_hover.png';
	srcArray[24] = '/fileadmin/templates/layouts/itplusx.de/images/buttons/button_clean_grey_send_hover.png';
	srcArray[25] = '/fileadmin/templates/layouts/itplusx.de/images/searchbox/lupe_hover.png';
	srcArray[26] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_kontakt_top.png';
	srcArray[27] = '/fileadmin/templates/layouts/itplusx.de/images/header/menu_tr.png';
	srcArray[28] = '/fileadmin/templates/layouts/itplusx.de/images/buttons/button_clean_grey_login.png';

	for (i = 0; i < srcArray.length; i++) {
		pic = new Image();
		pic.src = srcArray[i];
	}
});
