/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);

/*
 * Cookie plugin
 */
 
jQuery.cookie=function(a,b,c){if(arguments.length>1&&String(b)!=="[object Object]"){c=jQuery.extend({},c);if(b===null||b===undefined){c.expires=-1}if(typeof c.expires==="number"){var d=c.expires,e=c.expires=new Date;e.setDate(e.getDate()+d)}b=String(b);return document.cookie=[encodeURIComponent(a),"=",c.raw?b:encodeURIComponent(b),c.expires?"; expires="+c.expires.toUTCString():"",c.path?"; path="+c.path:"",c.domain?"; domain="+c.domain:"",c.secure?"; secure":""].join("")}c=b||{};var f,g=c.raw?function(a){return a}:decodeURIComponent;return(f=(new RegExp("(?:^|; )"+encodeURIComponent(a)+"=([^;]*)")).exec(document.cookie))?g(f[1]):null}

$(function(){
    
	/*
	 * Valid _blank function
	 */
	
	$('a[rel*=external],a[rel*=nofollow]').click(function() {
		window.open(this.href);
		return false;
	});
	
	/*
	 * Valid popup function
	 */
	
	$('a[rel*=share]').click(function() {
		var windowTitle = $(this).attr('title');
		window.open($(this).attr('href'), windowTitle, 'width=550,height=420,scrollbars=no');
		return false;
	});

    // header images cycle
    $('#banner_image').cycle({
        fx: 'fade',
        timeout: 10000,
        pagerEvent: 'mouseenter.cycle',
        before: checkQuote,
        pager: '#banner_nav',
        pagerAnchorBuilder: paginate
    });

    function paginate(ind, el) {
        if (ind == 0) return '<a href="' + $('#banner_image img:eq(0)').attr('rel') + '" id="tab1">' + $('#banner_image img:eq(0)').attr('alt') + '</a>';
        else if (ind == 1) return '<a href="' + $('#banner_image img:eq(1)').attr('rel') + '" id="tab2">' + $('#banner_image img:eq(1)').attr('alt') + '</a>';
        else if (ind == 2) return '<a href="' + $('#banner_image img:eq(2)').attr('rel') + '" id="tab3">' + $('#banner_image img:eq(2)').attr('alt') + '</a>';
        else if (ind == 3) return '<a href="' + $('#banner_image img:eq(3)').attr('rel') + '" id="tab4">' + $('#banner_image img:eq(3)').attr('alt') + '</a>';
    }
    function checkQuote(curr, next, opts) {
     //   alert('curr:'+opts.currSlide);
       // alert('next:'+opts.nextSlide);
       // alert(opts);
        $('#banner_quote div').removeClass('active');
        $('#quote'+(opts.nextSlide+1)).addClass('active');
    }
    $('#banner_quote div').removeClass('active');
    $('#quote1').addClass('active');
    
    function dump(obj) {
    var out = '';
    for (var i in obj) {
        out += i + ": " + obj[i] + "\n";
    }

    document.write(out);

    // or, if you wanted to avoid alerts...

    var pre = document.createElement('pre');
    pre.innerHTML = out;
    document.body.appendChild(pre)
}

    
    //content banners carousel
    $('#how_holder').jcarousel({visible: 4,scroll: 1,wrap: 'last',initCallback: mycarousel_initCallback});function mycarousel_initCallback(a){a.buttonNext.bind("click",function(){a.startAuto(0)});a.buttonPrev.bind("click",function(){a.startAuto(0)});a.clip.hover(function(){a.stopAuto()},function(){a.startAuto()})}$('#how_holder ul li').click(function(){window.location=$(this).attr('title');});
    
	//ContactUs Slider
	$('#contact_us').click(function() {
		$('#contactus_slider').animate({'top': '0px'});
	});
	$('#contactus_close').click(function() {
		$('#contactus_slider').animate({'top': '-275px'});
	});
    
    //Dropdown Menu
    $('ul.top_nav li.mNav:last').hoverIntent(
    	function() {
        	$('#productsDropdown19, #productsDropdown20, #productsDropdown196').fadeIn(600);
    	},function() {
    		$('#productsDropdown19, #productsDropdown20, #productsDropdown196').fadeOut(300);
    	}
    );
    
    
    
    $('#tweet_widget .twitterContent, #tweet_widget2').getTwitter({
    	userName: 'IndexSystems',
    	numTweets: 1,
    	loaderText: 'Tweet laden...',
    	slideIn: true,
    	slideDuration: 750,
    	showProfileLink: false,
    	showTimestamp: false
    });
    
    //how_right
    if ($('#how_holder ul li').length <= 4) {
        $('#how_right').hide();
    }
    
    $('#how_holder ul li').click(function(){
         window.location=$(this).attr('rel');
         return false;
    });
    
    //Share Dropdowns
	if( $.cookie('shareDropdown') != null ) { 
		$('.shareDropdown ul').css('display','block');
	}
    $('.shareDropdown h3').mousedown(function() {
    	$(this).css('background-position','2px bottom');
    }).mouseup(function() {
    	$(this).css('background-position','2px center');
    }).click(function() {
		if( $.cookie('shareDropdown') != null ) {
			$('.shareDropdown ul').slideUp('fast');
			$.cookie('shareDropdown', null);
		}
		else {
			$('.shareDropdown ul').slideDown('fast');
			$.cookie('shareDropdown', 1);
		}
    });
    
    $('#share_this').hoverIntent(function(){
    	$(this).css('background','#fff');
    	$(this).find('ul').slideDown('fast');
    },function(){
    	$(this).find('ul').slideUp('fast', function() {
    		$(this).parent().css('background','#383838');
    	});
    });
    
    //Social media icoontjes highlight
    $('footer.contactus_footer').children().hover(
		function() {
			$(this).siblings().stop().fadeTo(100,0.5);
		},
		function() {
			$(this).siblings().stop().fadeTo(300,1);
		}
	);
	
	//Widgetforms animations
	$('.callMeBack a').click(function() {
		$('#callMeBackForm').slideToggle();
		return false;
	});
	$('.getNewsletter a').click(function() {
		$('#getNewsletterForm').slideToggle();
		return false;
	});
    
    if ($('#youtubesrc')!=undefined) {
        if ($('#youtubesrc').val()!=undefined) {
            $('.youtubeImage').attr('src',$.jYoutube($('#youtubesrc').val()));
        }
    }
    
    //contactform validation
function Trim(inString) {
    var de_start = 0;
    var de_end = inString.length;
    while ((de_start < de_end) && (inString.charAt(de_start) == ' ')) {
        de_start++;
    }
    while ((de_end > 0) && (inString.charAt(de_end - 1) == ' ')) {
        de_end--;
    }
    return inString.substring(de_start, de_end);
}
function isValidEmail(str) {
    str = Trim(str);
    var pos = str.indexOf('@');
    if (str.length > 5) {
        if (str.indexOf(' ') == -1) {
            if (pos > 0 && pos < str.length - 4) {
                pos = str.indexOf('@', pos + 1);
                if (pos == -1) {
                    pos = str.length - str.lastIndexOf('.');
                    if (pos > 2 && pos < 6) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}

    
    $('#contactTrigger').click(function(){
        
        return_value = true;
        
        if ($('#yourName').val().length<2) {
           return_value = false;
           $('#yourName').addClass('error');
        } else {
            $('#yourName').removeClass('error');
        }
        
        if ($('#telephone').val().length<2) {
           return_value = false;
           $('#telephone').addClass('error');
        } else {
            $('#telephone').removeClass('error');
        }
        
        var contact_email = $('#email');
        if (!isValidEmail(contact_email.val())) {
            contact_email.addClass('error');
            return_value = false;
        } else {
            contact_email.removeClass('error');
        }

        
        return return_value;
    });
    
    $('#newsletterTrigger').click(function(){
        return_value = true;
        
        if ($('#yourName2').val().length<2) {
           return_value = false;
           $('#yourName2').addClass('error');
        } else {
            $('#yourName2').removeClass('error');
        }
        
        var contact_email = $('#email2');
        if (!isValidEmail(contact_email.val())) {
            contact_email.addClass('error');
            return_value = false;
        } else {
            contact_email.removeClass('error');
        }
        
        return return_value;
    });
    
	$('#search_form_input').focus(function() {
		if($(this).val() != 'Zoeken' || 'Search') {
			$(this).val('');
		}
	});
});
