jQuery.noConflict();

jQuery(document).ready(function() {

	// IE6 CACHE BACKGROUND IMAGES / NO FLICKER
	if(jQuery.browser.msie) {
		try {
			document.execCommand("BackgroundImageCache", false, true);
		} catch(err) {}
	}

});

function jquery_include(siteurl) {
	jquery_brancheview_include({id: 0});
}

// BRANCHE SUB PAGE
var jquery_branchemenu_loop_interval;
var jquery_branchemenu_loop_menu = 1;
var jquery_branchemenu_loop_count = 1;
var jquery_branchemenu_loop_total = 0;
function jquery_branchemenu_loop() {
	if(jquery_branchemenu_loop_total == 1) {
		window.clearInterval(jquery_branchemenu_loop_interval);
	} else {
		jquery_branchemenu_next();
	}
}
function jquery_branchemenu_set(mid) {
	jQuery('.brancheviewmenuitemleft').removeClass('selected');
	jQuery('.brancheviewmenuitemname').removeClass('selected');
	jQuery('.brancheviewmenuitemright').removeClass('selected');
	jQuery('.brancheviewmenuitem'+mid).addClass('selected');
}
function jquery_branchemenu_to(mid) {
	window.clearInterval(jquery_branchemenu_loop_interval);
	jquery_branchemenu_loop_count = parseFloat(mid);
	jquery_branchemenu_set(jquery_branchemenu_loop_count);
	var posleft = jquery_branchemenu_loop_count * 950;
	posleft = 0 - posleft;
	posleft = posleft + 950;
	posleft = posleft.toString();
	posleft = posleft + 'px';
	jQuery('ul.brancheviewwrapper').stop(true, true).animate({'left': posleft}, 1500, 'easeOutExpo', function() {
		window.clearInterval(jquery_branchemenu_loop_interval);
		jquery_branchemenu_loop_interval = window.setInterval('jquery_branchemenu_loop()', 6000);
	});
}
function jquery_branchemenu_next() {
	window.clearInterval(jquery_branchemenu_loop_interval);
	jquery_branchemenu_loop_count++;
	if(jquery_branchemenu_loop_count > jquery_branchemenu_loop_total) {
		jquery_branchemenu_loop_count = 1;
	}
	jquery_branchemenu_set(jquery_branchemenu_loop_count);
	var posleft = jquery_branchemenu_loop_count * 950;
	posleft = 0 - posleft;
	posleft = posleft + 950;
	posleft = posleft.toString();
	posleft = posleft + 'px';
	jQuery('ul.brancheviewwrapper').stop(true, true).animate({'left': posleft}, 1500, 'easeOutExpo', function() {
		window.clearInterval(jquery_branchemenu_loop_interval);
		jquery_branchemenu_loop_interval = window.setInterval('jquery_branchemenu_loop()', 6000);
	});
}
function jquery_branchemenu_prev() {
	window.clearInterval(jquery_branchemenu_loop_interval);
	jquery_branchemenu_loop_count--;
	if(jquery_branchemenu_loop_count < 1) {
		jquery_branchemenu_loop_count = jquery_branchemenu_loop_total;
	}
	jquery_branchemenu_set(jquery_branchemenu_loop_count);
	var posleft = jquery_branchemenu_loop_count * 950;
	posleft = 0 - posleft;
	posleft = posleft + 950;
	posleft = posleft.toString();
	posleft = posleft + 'px';
	jQuery('ul.brancheviewwrapper').stop(true, true).animate({'left': posleft}, 1500, 'easeOutExpo', function() {
		window.clearInterval(jquery_branchemenu_loop_interval);
		jquery_branchemenu_loop_interval = window.setInterval('jquery_branchemenu_loop()', 6000);
	});
}
function jquery_brancheview_include(object) {
	// ADD CLASS TO PRODUCTS
	jQuery('.pagebranchesubproducts > div').wrap('<div class="landproductboxfloat" />');
	// MENU
	jQuery('.branchmenuprev').bind('click', function() {
		jquery_branchemenu_prev();
	});
	jQuery('.branchmenunext').bind('click', function() {
		jquery_branchemenu_next();
	});
	// ANIMATION
	jQuery('.brancheview').each(function() {
		jQuery(this).find('.branchepointinfo').show().slideUp(0).css('visibility', 'visible');
		jQuery(this).find('.branchepoint').bind('mouseenter', function() {
			jQuery(this).find('.branchepointinfo').stop(true, true).slideDown('fast');
			jQuery(this).find('.branchepointicontext').stop(true, true).fadeOut('fast');
			jQuery(this).find('.branchepointicontextbg').stop(true, true).fadeOut('fast');
			jQuery(this).css('z-index', 4000);
		}).bind('mouseleave', function() {
			jQuery(this).find('.branchepointinfo').stop(true, true).slideUp('fast');
			jQuery(this).find('.branchepointicontext').stop(true, true).fadeIn('fast');
			jQuery(this).find('.branchepointicontextbg').stop(true, true).fadeTo('fast', 0.65);
			jQuery(this).css('z-index', 2000);
		});
		jQuery(this).find('.branchepointicontext').each(function() {
			var width = jQuery(this).width() + 25;
			if(width == 25) {
				width = jQuery(this).find('object').width() + 25;
			}
			var height = 26;
			var marginleft = 0 - width + 10;
			if(jQuery(this).hasClass('left')) {
				jQuery(this).css('margin-left', marginleft);
			}
			jQuery(this).parent('.branchepoint').find('.branchepointicontextbg').each(function() {
				if(jQuery(this).hasClass('left')) {
					jQuery(this).css('margin-left', marginleft);
				}
				jQuery(this).height(height).width(width).css('opacity', 0.75);
			});
		});
	});
	// COUNT
	if(jquery_branchemenu_loop_total == 0) {
		jquery_branchemenu_loop_total = jQuery('.brancheview').length;
	}
	// LOOP / INTERVAL
	//jquery_branchemenu_loop();
	window.clearInterval(jquery_branchemenu_loop_interval);
	jquery_branchemenu_loop_interval = window.setInterval('jquery_branchemenu_loop()', 6000);
	// EVENTS
	jQuery('.brancheviewslider').bind('mouseenter mouseover', function() {
		jQuery(this).parent('.brancheviewsliderwrapper').height(550);
		// INTERVAL
		window.clearInterval(jquery_branchemenu_loop_interval);
	}).bind('mouseleave', function() {
		jQuery(this).parent('.brancheviewsliderwrapper').height(350);
		// INTERVAL
		window.clearInterval(jquery_branchemenu_loop_interval);
		jquery_branchemenu_loop_interval = window.setInterval('jquery_branchemenu_loop()', 6000);
	});
	// SHOW MENU
	if(jQuery('.brancheview').length > 1) {
		jQuery('.brancheview').each(function() {
			jQuery('.branchemenuslider').append('<div class="brancheviewmenuitemleft brancheviewmenuitem'+jquery_branchemenu_loop_menu+'"></div><div class="brancheviewmenuitemname brancheviewmenuitem'+jquery_branchemenu_loop_menu+'" id="brancheviewmenuitem'+jquery_branchemenu_loop_menu+'" mid="'+jquery_branchemenu_loop_menu+'">'+jQuery(this).attr('menuname')+'</div><div class="brancheviewmenuitemright brancheviewmenuitem'+jquery_branchemenu_loop_menu+'"></div>');
			jquery_branchemenu_loop_menu++;
		});
		jQuery('.brancheviewmenuitemname').bind('mouseenter', function() {
			var midc = jQuery(this).attr('id');
			jQuery('.'+midc).addClass('over');
		}).bind('mouseleave', function() {
			var midc = jQuery(this).attr('id');
			jQuery('.'+midc).removeClass('over');
		}).bind('click', function() {
			var mid = jQuery(this).attr('mid');
			jquery_branchemenu_to(mid);
		});
		jquery_branchemenu_set(1);
		window.setTimeout("jQuery('.branchemenuslider').css('display', 'block').hide().slideUp(0).slideDown(1000, 'easeInOutQuad')", 500);
	}
}
