<!--
/* <documentation about="ABOUT javascript/default.js" type="GENERAL">
	<summary>This file is the default javascript file for Bonpack: it contains methods, calls and variables for all Bonpack pages
		Structure of this file:         
		1. Implementation of namespace Amersfoortse 
		2. Query.noConflict(): to avoid conflicts in jQuery library
		3. Definition global variables
		4. Bonpack.init(): start javascript app
		5. Specific functions
		6. Call Bonpack.init
	</summary>
	<namespace>Amersfoortse</namespace>
</documentation> */
var Bonpack = {};

 /* <documentation about="jQuery.noConflict()" type="Function call">
	<summary>Function is called to avoid conflicts among jQuery and other javascript used</summary>
</documentation> */
jQuery.noConflict();

/* global variables go here */


/* <documentation about="Bonpack.init" type="init function">
	<summary>This function containes all calls made to functions used on every page of Bonpack.
		It is initialized on document ready
	</summary>
	<namespace>Bonpack</namespace>
</documentation> */
Bonpack.init = function() {
	Bonpack.addOpenInLinksNewWindow();
	Bonpack.adjustKeywordsHeight();
	Bonpack.addProductGroupClick();
	
	jQuery("a#Cart").click(function () { Bonpack.showPopUp("./popups/step1.aspx"); return false; });		
	
}

/* <documentation about="Bonpack.addOpenInLinksNewWindow" type="specific function">
	<summary>Adds functionality that all links with type='new-window' will be opened in a new window</summary>
	<namespace>Bonpack</namespace>
	<param type="string" descr="Id of parent element; defaults to document if not supplied">parentElementId</param>
</documentation> */
Bonpack.addOpenInLinksNewWindow = function (parentElementId) {
	var container = "";
	if(parentElementId && parentElementId.length != 0) { container = "#" + parentElementId + " "; }
	var hyperlinks = jQuery(container + "a");
	
	for (var i=0; i < hyperlinks.length; i++) {
		if (hyperlinks[i].getAttribute("type") != "new-window") { continue; }
		
		jQuery(hyperlinks[i]).click(function () { window.open(this.href); return false; });		
	}
}

//function called from selectedindexchanged op language dropdown: set cookie so right language is loaded
//afer that reload page so right xml content (translation) can be loaded
Bonpack.setCulture = function(dropDown)
{
    Bonpack.setCookie("UserCulture", dropDown.options[dropDown.selectedIndex].value, true);
    location.href=location.href;
}

//sets cookkie
Bonpack.setCookie = function(name, value, expires ) 
{
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires ) { expires = expires * 1000 * 60 * 60 * 31;  }
    var expires_date = new Date( today.getTime() + (expires) );
    document.cookie = name+"="+escape( value ) + ( ( expires ) ? ";expires="+expires_date.toGMTString() : "" ) 
}



/* <documentation about="Bonpack.adjustKeywordsHeight" type="specific function">
	<summary>Adjust height of keywords in ProductGroups</summary>
	<namespace>Bonpack</namespace>
</documentation> */
Bonpack.adjustKeywordsHeight = function () {
	if(jQuery("body.productgroups").length==0) return; 
	
	var types = jQuery(".types");	
	var maxHeight = 0; 
	for (var i=0; i < types.length; i++) {
		if(maxHeight < jQuery(types[i]).height()) { maxHeight = jQuery(types[i]).height(); }
	}
	//jQuery(".group-tab .types ").attr("style", "min-height:" + maxHeight + "px");
	
	var keywords = jQuery(".keywords");	
	maxHeight = 0; 
	for (var i=0; i < keywords.length; i++) {
		if(maxHeight < jQuery(keywords[i]).height()) { maxHeight = jQuery(keywords[i]).height(); }
	}
	jQuery(".group-tab .keywords ").attr("style", "height:" + maxHeight + "px");
}

Bonpack.addProductGroupClick = function () {
    if(jQuery("body.productgroups").length==0) return; 
	
	jQuery(".group-tab a").click(function () {  location.href = this.href; return false; }).mouseover(function () { jQuery(this).parent().parent().parent().parent().removeClass("hover"); return false; });		
	
	var redirect = function(groupTabId) {
	    location.href = jQuery("#" + groupTabId + " h2 a").attr("href"); 
	}
	
	jQuery(".group-tab h2 a").mouseover(function () { jQuery(this).parent().parent().addClass("hover");  }).mouseout(function () { jQuery(this).parent().parent().removeClass("hover"); });	
	jQuery(".group-tab .types").click(function () { redirect(jQuery(this).parent().attr("id")); return false; }).mouseover(function () { jQuery(this).parent().addClass("hover");  }).mouseout(function () { jQuery(this).parent().removeClass("hover"); });		
	jQuery(".group-tab .keywords").click(function () { redirect(jQuery(this).parent().attr("id")); return false; }).mouseover(function () { jQuery(this).parent().addClass("hover");  }).mouseout(function () { jQuery(this).parent().removeClass("hover"); });		
}

/* <documentation about="Bonpack.showPopUp" type="specific function">
<summary>Opens overlay and popup window</summary>
<namespace>Bonpack</namespace>
<param type="string" descr="pagename">page</param>
</documentation> */
Bonpack.showPopUp = function (page) {
    jQuery("div.help-text").hide(); //reset: hide all active help-text panels
    
    var left = Bonpack.findElementPosition(jQuery("#Main")[0])[0];
	
    jQuery("#PageContainer").before(jQuery("<div id=\"CoverScreen\"></div>" +
        "<div id=\"PopUpHolder\" style=\"left:" +  left + "px\"><iframe id=\"PopUpIframe\" frameborder=\"0\" scrolling=\"no\" src=\"" + page + "\"></iframe></div>" +
        "<div id=\"CartActive\" style=\"left:" +  (parseInt(left) + 730) + "px\"></div>"));
    
    jQuery("#CoverScreen").css("opacity", 0).css("background-color", "#787878");
    jQuery("#CoverScreen").animate({opacity:0.5},1000, function() { jQuery("#CartActive").show() } );
    //jQuery("#CoverScreen").click(function() { Bonpack.removePopUp(); });
    Bonpack.scrollToTop();        
}

Bonpack.scrollToTop  = function (page) {
    jQuery.scrollTo(0, {speed:1000}  );        
}


/* <documentation about="Bonpack.removePopUp" type="specific function">
<summary>Removes overlay and popup window</summary>
<namespace>Bonpack</namespace>
</documentation> */
Bonpack.removePopUp = function () {
    jQuery("#CoverScreen").animate({opacity:0},1000, function() { jQuery("#CoverScreen").remove(); });
    jQuery("#PopUpHolder").remove();
    jQuery("#CartActive").remove();
}

/* <documentation about="Bonpack.removeActiveCart" type="specific function">
<summary>Removes active cart</summary>
<namespace>Bonpack</namespace>
</documentation> */
Bonpack.removeActiveCart = function (cartText) {
   jQuery("#CartActive").remove();
   jQuery("#Cart span").text(cartText);
}

/* <documentation about="Bonpack.setActiveCartValue" type="specific function">
<summary>Set value of cart and  active cart</summary>
<namespace>Bonpack</namespace>
</documentation> */
Bonpack.setActiveCartValue = function (cartText) {
   jQuery("#CartActive").text(cartText);
   jQuery("#Cart span").text(cartText);
}

/* <documentation about="Bonpack.findElementPosition" type="general function">
	<summary>Find position of a HTML element relative to window</summary>
	<namespace>Bonpack</namespace>
	<param type="object" descr="HTML element">elem</param>
	<returns>array [left (integer), top (integer)]</returns>
</documentation> */
Bonpack.findElementPosition = function (elem){
	var curleft = curtop = 0;
	if (elem.offsetParent) {
	
		curleft = elem.offsetLeft
		curtop = elem.offsetTop
		while (elem = elem.offsetParent) {
			curleft += elem.offsetLeft
			curtop += elem.offsetTop
		}
	}
	return [curleft,curtop];
}

 /* <documentation about="Bonpack.resizeExtraInfoIframe" type="specific function">
<summary>Resizes iframe extra info</summary>
<namespace>Bonpack</namespace>
</documentation> */
Bonpack.resizeFrameHolder = function (newHeight) {
    
   jQuery("#PopUpIframe").animate({ height:newHeight}, 500);
} 
 
jQuery(document).ready(function(){ Bonpack.init(); });     	
//-->

