// navigation.js

/* fix the pngs in ie6 */
$(document).ready(function() {
	$('img[@src$=.png]').ifixpng(); 
});

/* product shortcut images ie6 hack */
$(document).ready(function() {
	$('dl.product dd a').hover(function() {
		$(this).find('span').show(0);
	}, function() {
		$(this).find('span').hide(0);
	});
});

/* submenu slidedown */
$(document).ready(function() {
	items = $('#submenu > ul > li > ul > li');
	
	items.find('> a').click(function() {
		if($(this).parent().find('> ul').css('display') == 'none') {
			$(this).parent().find('> ul:hidden').slideDown(100);
			return false;
		}
		
		else if($(this).parent().find('> ul > li > ul').css('display') == 'none') {
			$(this).parent().find('> ul > li > ul:hidden').slideDown(100);
			return false;
		}
		
		else if($(this).parent().find('> ul').css('display') == 'block') {
			$(this).parent().find('> ul > li > ul:visible').slideUp(100);
			return false;
		} 
		
		else if($(this).parent().find('> ul > li > ul').css('display') == 'block') {
			$(this).parent().find('> ul:visible').slideUp(100);
			return false;
		}
		
		else {
			return true;
		}
	});
});

/* product types slide down*/
$(document).ready(function() {
	if($.browser.msie && parseInt($.browser.version) == 6) {
		//return;
	};
	
	types = $("#content div.type");
	
	types.each(function() {
		$(this).find('.products').hide(0);
		
		//$(this).find('.description a.show').show(0);
		//$(this).find('.products a.hide').show(0);
	});
	
	types.find('.description a.show').click(function() {
		$(this).parent().parent().find('.products').slideDown(100);
			
		$(this).hide(0);
		
		return false;
	});
	
	types.find('.products a.hide').click(function() {
		$(this).parent().slideUp(100);
		$(this).parent().parent().find('.description a.show').show(0);
		
		return false;
	});
});

/* items slidedown */
$(document).ready(function() {	
	sliders = $('div.list dl.item_slide dt');
	
	sliders.find('a.show').click(function() {
		$(this).hide();
		$(this).parent().find('a.hide').show(0);
		
		$(this).parent().find('span.clone').hide(0);
		$(this).parent().find('span.origin').show(0);
		
		return false;
	});
	
	sliders.find('a.hide').click(function() {
		$(this).hide();
		$(this).parent().find('a.show').show(0);
		
		$(this).parent().find('span.origin').hide(0);
		$(this).parent().find('span.clone').show(0);
		
		return false;
	});
	
	sliders.each(function() {
		$(this).find('a.hide').hide(0);
		
		slider = $(this).find('span');
		slider.css('cursor', 'pointer');
		
		origin = $(this).find('span.origin');
		origin_text = origin.text();
		origin.hide(0);
		
		clone = $(this).find('span.clone');
		
		if(origin.height() > 117) {
			clone.text(origin_text.slice(0, 220) + '...');
		} else {
			slider.unbind();
			slider.css('cursor', 'default');
			clone.text(origin_text);
			$(this).find('a.show').hide(0);
		}
	});
});

/* software slideshow */
$(document).ready(function() {
	var parent = $('div.slider');
	
	var origin = $('div.slider div.origin span');
	var origin_children = origin.children();
	var clone = $('div.slider div.clone span');
	
	if(origin_children.size() > 2) {
		// clone the children
		clone.html(origin.html());
		clone.children().slice(2).remove();
		
		// hide the parent (original)
		origin.hide(0);
		parent.find('a.hide').hide(0);
	}
	
	parent.find('a.show').click(function() {
		$(this).hide();
		$(this).parent().find('a.hide').show(0);
		
		origin.show(0);
		clone.hide(0);
		
		return false;
	});
	
	parent.find('a.hide').click(function() {
		$(this).hide();
		$(this).parent().find('a.show').show(0);
		
		origin.hide(0);
		clone.show(0);
		
		return false;
	});
});

/* software downloads version history */
$(document).ready(function() {
	$('.downloads .expander').click(function() {
		$(this).parents('tr').next().toggle(); //slideToggle(200)
		//$(this).html( ($(this).html() == '+') ? '-' : '+' );
	});
});

/* search box */
$(document).ready(function() {
	$('#search input.text').focus(function() {
		$(this).val('');
	});
});

/* partner search */
$(document).ready(function() {
	$('#form_partner select').change(function() {
		field = $(this);
		value = field.val();
		
		if((field.attr('id') == 'frm_country' || field.attr('id') == 'frm_territory') && field.val() != '') {
			$('#frm_country').attr('disabled', 'disabled').val('');
			$('#frm_territory').attr('disabled', 'disabled').val('');
			
			field.removeAttr('disabled').val(value);
		} else if ((field.attr('id') == 'frm_country' || field.attr('id') == 'frm_territory') && field.val() == '') {
			$('#form_partner select').removeAttr('disabled');
		}
	});
});

/* downloads language selector */
$(document).ready(function() {
	$('#downloads_language select').change(function() {
		$(this).parent().parent().submit();
	});
});


/* box headlines */
$(document).ready(function() {
	if($('#stage > #layout > #content > #header h2').children().size() == 0) {
		$('#stage > #layout > #content > #header h2').wrapInner('<span></span>');
	}
});