
jQuery.noConflict();
// JavaScript Document
jQuery(document).ready(function(){
						   
/*
if (jQuery(".darkRow img").attr("src")="/images/features_yes.gif"){
	jQuery(this).attr(src, "/images/features_yes_grey_bk.gif")
}
*/

jQuery(".comparisonTable tr:odd").addClass("darkRow");



/*
-----------------------------------------------
/ PO6 PRO ADDITIONS
-----------------------------------------------
*/

if (jQuery("#newsletterPopup").size() > 0){
	
	jQuery("#newsletterPopup .watchVideoLater, #newsletterPopup .watchVideo").fancybox({
			overlayShow: true,
			frameWidth:640,
			frameHeight:360
		}).click(function() { 
			jQuery('#jquery-lightbox').click();
			jQuery('#fancy_title').html(jQuery(this).parent().html());
			jQuery('#fancy_title a').hide();
			return true; 
		});
	
	jQuery("#newsletterPopup .watchVideoLater, #newsletterPopup .watchVideo").click();
	
}




jQuery('.menuArea').hover(
	function() {
	    jQuery(this).addClass('active');
	    jQuery('#megaDropdown').show();
	},
	function() {

	    jQuery('#megaDropdown').hide();
	}
);

if (jQuery('#accordion').length > 0) {
	var activeTab;
	
	if(location.hash[0] == '#') {
		activeTab = parseInt(location.hash.slice(1)) - 1;
	} else {
		activeTab = (typeof option == 'undefined') ? 0 : (option - 1);
	}

    jQuery('#accordion')
		.accordion({ 
			active: activeTab, 
			collapsible:true,
			change: function(e,u) {
				if(u.options.active != false) {
					location.hash = u.options.active + 1;
				}
				
				if(u.options.active == 0) location.hash = 1;
			}
		});
    jQuery('.ui-state-active').removeClass('ui-state-default');
}

jQuery(".comparisonTable tr:odd").addClass("darkRow");

if(jQuery('.lb').length > 0)
	jQuery('.lb')
		.lightBox()
		.click(function() {
			jQuery('#lightbox-container-image-data-box')
				.html('<div style="color: #77787A; font-size: 12px; line-height: 17px; font-family: arial;">' + jQuery(this).parent().html() + '</div>')
				.css({
					'text-align': 'left',
					'padding': '10px'
				});
			
			jQuery('#lightbox-nav #lightbox-nav-btnPrev, #lightbox-nav #lightbox-nav-btnNext').remove();
			
			jQuery('#lightbox-image')
				.click(function(e) {
					e.preventDefault();
					jQuery(this).parent().parent().parent().find('a.watchVideoLater').click();
					return false;
				})
				.css('cursor', 'pointer');

			jQuery('#lightbox-nav')
				.click(function(e) {
					e.preventDefault();
					jQuery(this).parent().parent().parent().find('a.watchVideoLater').click();
					return false;
				})
				.css('cursor', 'pointer');
			
			jQuery('#lightbox-container-image-data-box img').hide();
			jQuery('#lightbox-nav').append('<img src="/images/CAP/fancy_closebox.png" border="0" id="close_lightbox" />');
			jQuery("a.watchVideoLater[rel=fancyvideo]").fancybox({
						overlayShow: true,
						frameWidth:640,
						frameHeight:360
					}).click(function() { 
						jQuery('#jquery-lightbox').click();
						jQuery('#fancy_title').html(jQuery(this).parent().html());
						jQuery('#fancy_title a').hide();
						return true; 
					});
		});

if((jQuery("a.popup-link").length > 0) && (jQuery("a[rel=fancyvideo]").length > 0)) { //this count take a little time to execute, and some browsers start folowing the link before the js is executed
	jQuery("a[rel=fancyvideo]")
		.fancybox({
			overlayShow: true,
			frameWidth:640,
			frameHeight:360
		})
		.click(function() {
			jQuery('#fancy_title').html('<h2>' + jQuery(this).siblings('h2').html() + '</h2><p>'  + jQuery(this).siblings('span.hidden').html() + '</p>');
		})
		.siblings('.watchVideo').click(function() {
			jQuery(this).siblings('a[rel=fancyvideo]').click();
			return false;
		});
}// ending the if above

if(jQuery('a[rel=fancyvideolink]').length > 0) {
	jQuery('a[rel=fancyvideolink]').each(function() {
		jQuery(this).fancybox({
			overlayShow: true,
			frameWidth:640,
			frameHeight:360
		})
		.click(function() {
			jQuery('#fancy_title').html('<h3>' + jQuery(this).html() + '</h3>' + (jQuery(this).siblings('span.hidden').length > 0 ? jQuery(this).siblings('span.hidden').html() : ''));
		});
	});
}

if(jQuery('a.lb').length > 0) {
	jQuery('a.lb').each(function() {
			if(jQuery(this).children('img').length == 0) return true;
	
			var posTop = 100;
			var posLeft = 90;
	
			if(jQuery(this).hasClass('popup-link')) {
				jQuery(this)
					.children('img')
					.after('<img class="enlargeImage" border="0" src="/images/CAP/EnlargeVideo.png" style="border:0;display:none;position:absolute;top:'+ posTop +'px; left: '+ posLeft +'px;" />');
			} else {
				jQuery(this)
					.children('img')
					.after('<img class="enlargeImage" border="0" src="/images/CAP/Enlarge.png" style="border:0;display:none;position:absolute;top:'+ posTop +'px; left: '+ posLeft +'px;" />');
			}
	
			jQuery(this).mouseover(function() {
				jQuery(this).children('.enlargeImage').fadeIn('fast');
			}).mouseout(function() {
				jQuery(this).children('.enlargeImage').fadeOut('fast');
			});
	});
}

// Menu grouping (8 per row minimum)

if(jQuery('#megaDropdown').length > 0) {
	var lists = new Array();
	
	jQuery('#megaDropdown ul').each(function(i, el) {
		lists[i] = el;
	});
	
	jQuery.each(lists, function(i,el) {
		if(i == 0) return true;
		
		if(jQuery(lists[i]).children('li').length + jQuery(lists[i - 1]).children('li').length <= 8) { // 8 per row
			jQuery(lists[i-1]).append(jQuery(lists[i]).html());
			jQuery(lists[i]).remove();
		}
	});
}

if(jQuery('.comparisonHeading td').length == 2) {
	jQuery('td.checkbox').css('width', '90px');
}

/*
-----------------------------------------------
-----------------------------------------------
*/

function getQuerystring(key, default_)
{
if (default_==null) default_="";
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
else
return qs[1];
}

if (getQuerystring('openpopup')=="yes"){
	
var popupUrl = "/layouts/Nemetos/PopupVideo.aspx?url=" + getQuerystring('url');

if(jQuery('a.watchVideoLater[href=' + getQuerystring('url') + ']:first').length > 0) {
	// Video available on page
	jQuery('a.watchVideoLater[href=' + getQuerystring('url') + ']:first').click();
} else {
	if(jQuery('.popup-link').length > 0) {
		jQuery(".popup-link").each(function (i) {
			var linkID = jQuery(this).attr("id");
			var linkIDSplitNr = linkID.lastIndexOf('&vID');

			linkID = linkID.substr(0,linkIDSplitNr);

			if (linkID == popupUrl){
				jQuery(this).trigger('click');
			}
		});
	} else {
	
		// Video not available
		jQuery('body').append('<span id="triggeredPopup" style="display:block; visibility: hidden; height: 0px; width: 0px;"><a target="_blank" rel="fancyvideo" href="' + getQuerystring('url') + '"></a></span>');
	
		jQuery('span#triggeredPopup a').fancybox({ frameWidth:640, frameHeight:360, overlayShow: true }).click();
	
		jQuery('div#fancy_wrap').css({
			'position': 'absolute',
			'top': '15px',
			'z-index': '999'
		});
	
		jQuery('div#fancy_title').html('<h2>YouTube link</h2><a style="color: #00D" href="' + getQuerystring('url') + '" target="_blank">' + getQuerystring('url') + '</a>');
	}
}


/*

jQuery(".popup-link").each(function (i) {
										 
var linkID = jQuery(this).attr("id");
		
var linkIDSplitNr = linkID.lastIndexOf('&vID');
		
linkID = linkID.substr(0,linkIDSplitNr);

if (linkID == popupUrl){


jQuery(this).trigger('click');;	
			
			
}
	
}); */
	

	
}



/*
jQuery(".communityToolsList ul li:eq(1) a:last").click(
function () {
jQuery("#GB_window").append('<input id="btnCancel" class="mailButton" type="submit" title="Cancel" value="Cancel" name="btnCancel"/>');
});
*/








jQuery(function(){jQuery("#headerLogo, .communityToolsList").pngfix();});



/*
jQuery("tr:not(.darkRow) img").each(function (i) {	
	if (jQuery(this).attr("src") = "/images/features_yes_grey_bk.gif"){
		jQuery(this).attr(src, "/images/features_yes_grey_bk.gif")
	}
});
*/
/*
-----------------------------------------------
/ Equalize height of the Graphic Teasers on the same line
-----------------------------------------------
*/ 

equalizeHeight(".teasers .textTeaser", ".wideTeasersArea", ".teaserWide", ".textTeaser h3", ".textTeaser .textTeaserTxt");
equalizeHeight(".teasers .graphicTeaser", ".wideTeasersArea", ".teaserWide", ".graphicTeaser h2", ".graphicTeaserTxt");
equalizeHeight2Cols(".wideTeasersArea .teaserWide", ".wideTeasersArea", ".teaserWide", ".teaserWide h3", ".teaserWideContent");

function equalizeHeight(placeHolder, container, itemName, itemHeadline, itemBody){
	var placeHolder = placeHolder;
	var container = container;
	var itemName = itemName;
	var itemHeadline = itemHeadline;
	var itemBody = itemBody;

	jQuery(placeHolder).each(function (i) {								
		if ( (i % 3) == 0){
			teaserTitleHeight = jQuery(itemHeadline).eq(i).height();
			if (teaserTitleHeight < jQuery(itemHeadline).eq(i+1).height()){
				teaserTitleHeight = jQuery(itemHeadline).eq(i+1).height();
			}
			if (teaserTitleHeight < jQuery(itemHeadline).eq(i+2).height()){
				teaserTitleHeight = jQuery(itemHeadline).eq(i+2).height();
			}		
			jQuery(itemHeadline).eq(i).height(teaserTitleHeight + "px");
			jQuery(itemHeadline).eq(i+1).height(teaserTitleHeight + "px");
			jQuery(itemHeadline).eq(i+2).height(teaserTitleHeight + "px");
			
			
			teaserBodyHeight = jQuery(itemBody).eq(i).height();
			if (teaserBodyHeight < jQuery(itemBody).eq(i+1).height()){
				teaserBodyHeight = jQuery(itemBody).eq(i+1).height();
			}
			if (teaserBodyHeight < jQuery(itemBody).eq(i+2).height()){
				teaserBodyHeight = jQuery(itemBody).eq(i+2).height();
			}		
			jQuery(itemBody).eq(i).height(teaserBodyHeight + "px");
			jQuery(itemBody).eq(i+1).height(teaserBodyHeight + "px");
			jQuery(itemBody).eq(i+2).height(teaserBodyHeight + "px");

		}

	});

}

function equalizeHeight2Cols(placeHolder, container, itemName, itemHeadline, itemBody){
	var placeHolder = placeHolder;
	var container = container;
	var itemName = itemName;
	var itemHeadline = itemHeadline;
	var itemBody = itemBody;

	jQuery(placeHolder).each(function (i) {								
		if ( (i % 2) == 0){
			teaserTitleHeight = jQuery(itemHeadline).eq(i).height();
			if (teaserTitleHeight < jQuery(itemHeadline).eq(i+1).height()){
				teaserTitleHeight = jQuery(itemHeadline).eq(i+1).height();
			}
			jQuery(itemHeadline).eq(i).height(teaserTitleHeight + "px");
			jQuery(itemHeadline).eq(i+1).height(teaserTitleHeight + "px");
			
			
			teaserBodyHeight = jQuery(itemBody).eq(i).height();
			
			if (teaserBodyHeight < jQuery(itemBody).eq(i+1).height()){
				teaserBodyHeight = jQuery(itemBody).eq(i+1).height();
			}
			if (teaserBodyHeight < 103){
				teaserBodyHeight = 103;
			}
			jQuery(itemBody).eq(i).height(teaserBodyHeight + "px");
			jQuery(itemBody).eq(i+1).height(teaserBodyHeight + "px");

		}

	});

}

jQuery(".compareToProductList").hover(
	  function () {
			jQuery(this).children("ul").css("display", "block");
	  }, 
	  function () {
			jQuery(this).children("ul").css("display", "none");
	  }
);

jQuery(".chooseLanguageList").hover(
	  function () {
			jQuery(this).children("ul").css("display", "block");
	  }, 
	  function () {
			jQuery(this).children("ul").css("display", "none");
	  }
);
	
/*
jQuery(".communityToolsHeader").hover(
  function () {
		jQuery(this).children(".communityToolsSubItem").css("display", "block");
  }, 
  function () {
		jQuery(this).children(".communityToolsSubItem").css("display", "none");
  }
);
*/

jQuery(".chooseLanguage, .communityTools li").hover(
  function () {
		jQuery(this).addClass("hover");
  }, 
  function () {
		jQuery(this).removeClass("hover");
  });

jQuery(".communityTools > ul > li").hover(
  function () {
			jQuery(this).children("ul").parent().addClass("hasChildren");
  }, 
  function () {
		jQuery(".communityTools li").removeClass("hasChildren");
});

  
/*
-----------------------------------------------
/ Equalize height of the Text Teasers on the same line
-----------------------------------------------
*/ 

/*** TABS ***/
/* fixed height for all panels !!! is this needed? */
var tallest = 0;
jQuery('#tabPanels div').each(function(i){
	thisHeight = jQuery(this).height();
	if(thisHeight > tallest) {
		tallest = thisHeight;
		//jQuery(this).height(tallest);
	}
});


/*** end TABS ***/







// if there are less than three teasers on a row, we need to clear the content or it won't take into consideration the .graphicTeaser{margin-bottom: 10px;}
if(jQuery.browser.msie){
     jQuery(".teasers").append('<br style="clear: both;" />');
}

});


