
/*******************************************************************************
 * Basket script
 *******************************************************************************/
function Basket(maxLineItemQuantity, quantityErrorMessage) {

	this.requisition = $("form[name=CurrentReq]");
	this.maxLineItemQuantity = maxLineItemQuantity;
	this.quantityErrorMessage = quantityErrorMessage;

	// bind events
	var self = this;

	$(".update", self.requisition).click(function() {
		self.update(true);
		return false;
	});
	$(".next", self.requisition).click(function() {
		self.checkout();
		return false;
	});
	$("input.quantity", self.requisition).keydown(function(e) {
		if (e.keyCode == "13") {
			self.update(true);
			return false;
		}
	});		
	$(".delivery input.radio").click(function() {
		self.shipChange();
	});
	
	this.checkQuantities();
}

/**
method is called if Shipping Method is changed by user.
Switches the flows.
*/
Basket.prototype.shipChange = function() {
	// submit form which will cause a page reload with the new shipping method
	this.update(false);
}

Basket.prototype.doSubmit = function() {

	if(!this.checkQuantities()) {
		return false;
	}
	return true;
}

/**
  updates the basket. quantity check is done on browser first
*/
Basket.prototype.update = function(doCheck) {

	if (!doCheck || this.checkQuantities()) {
		$("#basketDispatchAction", this.requisition).attr("name", "update");
		this.requisition.submit();
	}
}

/**
checkout the basket. Quantity check is done on browser first
*/
Basket.prototype.checkout = function() {

	if (this.checkQuantities()) {
		$("#basketDispatchAction", this.requisition).attr("name", "checkout");
		this.requisition.submit();
	}
}

/**
  no PLI is allowed to contain more than 'Requisition.MaxLineItemQuantity' items
*/
Basket.prototype.checkQuantities = function() {
	
	var self = this;
	var valid = true;
	$("input", this.requisition).each(function(i, e) {
		
		if (e.name.indexOf('Quantity_') == 0) {
			
			var value = $(e).val();
			if (isNaN(value) || (Number(value) > self.maxLineItemQuantity) || (Number(value) == 0)) {
				$(e).css("border", "1px solid #d90011");
				valid = false;
			} else {
				$(e).css("border-color", "");
			}	
		}
	});

	if (!valid) {
		$(".error", this.requisition).hide();
		$(".error", this.requisition).html(this.quantityErrorMessage);
        $(".error", this.requisition).fadeIn();
	}
	return valid;
}

/**
 * pre_PostLogin function
 */
function pre_PostLogin(form_selector) {
	var params = [];
	if ($("#postlogin_postloginpipeline").length) {
		$('input[name=PostLoginPipeline]').val($("#postlogin_postloginpipeline").val());
		//params.push({name:'PostLoginPipeline',value:$("#postlogin_postloginpipeline").val()});
		if ($("#postlogin_context").length) {
			$('input[name=context]').val($("#postlogin_context").val());
		}
		for (i=1; i<10; i++) {
			if ($("#postlogin_paramname"+i).length && $("#postlogin_paramvalue"+i).length) {
				params.push({name:$("#postlogin_paramname"+i).val(),value:$("#postlogin_paramvalue"+i).val()});
			}
		}
		
		// add extra params to the url action
		if ($("#postlogin_extraparam_container").length) {
			container_id = $("#postlogin_extraparam_container").val();
			// check param container really exist
			containerSelector = getIDSelector(container_id);
			var extra_params = $(containerSelector + " *").serialize();
			if (extra_params) {
				old_action = $(form_selector).attr("action");
				$(form_selector).attr("action", old_action + "&" + extra_params);
			}
		}
	}
	
	// add post login params to the form
    $.each(params, function(i,param){
        $('<input />').attr('type', 'hidden')
            .attr('name', param.name)
            .attr('value', param.value)
            .appendTo(form_selector);
    });
    
    //$("#"+formname).submit();
}

/**
 * general function for setting columns of a table with same height
 */
function sameHeight() {
	var tallest = 0;
	var elements = jQuery('.sameHeight');
			
	elements.each(function() {
		var thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	
	if(elements.size()>0)	
		elements.height(tallest);
}
jQuery(document).ready(function() {
	sameHeight();
});

/*******************************************************************************
 * General initalization
 *******************************************************************************/
jQuery(document).ready(function() {

	// add login forms submit handlers
	function loginFormHandler(form_selector, button_selector, user_selector, password_selector) {
		
		var login_form = $(form_selector);	
		$(button_selector, login_form).click(function() {
			pre_PostLogin(form_selector);
			login_form.submit();
			return false;
		});
		$(user_selector, login_form).keypress(function(e) {
			if (e.keyCode == 13) {
				pre_PostLogin(form_selector);
				login_form.submit();
			}
		});
		$(password_selector, login_form).keypress(function(e) {
			if (e.keyCode == 13) {
				pre_PostLogin(form_selector);
				login_form.submit();
			}
		});
	}
	
	loginFormHandler("#header .loginForm", "a#login-btn", "#lgn-email", "#lgn-password");
	loginFormHandler("#teaser .teaserPale .form", "a.buttonLeftRevDark", "#email", "#password");
	loginFormHandler("#main .loginForm", "#anmelden", "#login", "#password");

	// add forgot password submit handler
	var forgot_password_form = $(".forgotPasswordForm");
	$("a#send", forgot_password_form).click(function() {
		forgot_password_form.submit();
		return false;
	});
	$("input#email", forgot_password_form).keypress(function(e) {
		if (e.keyCode == 13) forgot_password_form.submit();
	});
	
	// handle default focus
	$("#right-content .loginForm #email").focus();
	
	if ($.browser.msie && $.browser.version=="6.0") {

		// position:fixed workaround for footer
		var footer = $("#footer");
		footer.css("position", "absolute");
		
		var handler = function() {
			footer.css("top", ($(window).innerHeight() - footer.height() + $(window).scrollTop()) + "px");
		}
		
		// must use bind() since jQuery scroll overwrites it
		$(window).bind("scroll", handler);
		$(window).resize(handler);	
	}
	

	// fixed agency tile script
	jQuery('.productRow').each(function(){
		var maxHeight = 0;
		jQuery(this).children('.productTile').children('.productDescription').each(function(){

			var height1 = $(".head", this).outerHeight(true);
			var height2 = $(".productText", this).outerHeight(true)

			var height = height1 + height2;
			if (height > maxHeight) maxHeight = height;
		});
		
		jQuery(this).children('.productTile').children('.productDescription').css('height', maxHeight+"px");
	});	

	
	/*******************************************************************
	 * SPPS Popup
	 *******************************************************************/
	jQuery('.modalLayerServiceRequest').click(function(evt){
	    if(jQuery(evt.target).hasClass('modalLayerServiceRequest')||jQuery(evt.target).hasClass('modalContentServiceRequest'))
	    {
	        //togglePopup();
	    }

	});

	jQuery('.modalContentServiceRequest').click(function(evt){
	    if(jQuery(evt.target).hasClass('modalLayerServiceRequest')||jQuery(evt.target).hasClass('modalContentServiceRequest'))
	    {
	        //togglePopup();
	    }

	});
  
});

function autoresize_frames(iframeid) {
	var framefenster = document.getElementById(iframeid);
    
    if(framefenster.contentWindow.document.body){
      var framefenster_size = framefenster.contentWindow.document.body.offsetHeight;
      if(document.all && !window.opera) {
        framefenster_size = framefenster.contentWindow.document.body.scrollHeight;
      }
      framefenster.style.height = framefenster_size + 'px';
    }
  }

function togglePopup()
{
	jQuery('.modalLayerServiceRequest').toggleClass('hidden');
	jQuery('.modalContentServiceRequest').toggleClass('hidden');
	$.modal.close();
}

function RemoveVehicleDatas(){
	/*$('#PersonalVehicleForm_CarClassKey').val('');
	$('#PersonalVehicleForm_ModelYearKey').val('');
	$('#PersonalVehicleForm_CarNumber').val('');
	$('#PersonalVehicleForm_ModelTypeKey').val('');
	$('#PersonalVehicleForm_FIN').val('');*/
	
	$('#ForceSubmitVehicleForm').val('');
}


function validateVehicleForm() {	
	service = $("input[name=PersonalVehicleForm_ServiceCode]");
	if (service.length) {
		return validateAssystPlusForm();
	} else {
		servDate = $("input[name=PersonalVehicleForm_DateLastService]");
		if (servDate.length) {
			return validateAssystABForm();
		}
	}
	return "";
}

function markFieldError(field) {
	if ((field == null) || (field === "")) return
	td = field.closest("td")
	
	if (td.length) {
		$(td).addClass("cdError");

		tdLabel = $("#td_" + $(field).attr("name") + " div");
		if (tdLabel.length) {
			$(tdLabel).addClass("error_message");
		} else {
			tdLabel = $("#td_" + $(field).attr("name"));
			if (tdLabel.length) {
				thtml = $(tdLabel).html();
				$(tdLabel).html("<div class='error_message'>" + thtml + "</div>");
			}
		}
	}
}

function removeFieldError(field) {
	if ((field == null) || (field === "")) return
	td = field.closest("td")
	
	if (td.length) {
		$(td).removeClass("cdError");

		tdLabel = $("#td_" + $(field).attr("name") + " div");
		if (tdLabel.length) {
			$(tdLabel).removeClass("error_message");
		}
	}
}

function validateAssystPlusForm() {
	// get form
	f = $("select[name=PersonalVehicleForm_CarClassKey]");
	if (f.length)
		f = f.closest("form");

	// attach form validation
	if (f.is("form")) {
		servicetype = $("select[name=PersonalVehicleForm_ServiceType]");
		service = $("input[name=PersonalVehicleForm_ServiceCode]");
		workshop = $("input[name=PersonalVehicleForm_WorkshopCode]");
		var servicetypeValue = "";
		var serviceValue = "";
		var workshopValue = "";
		
		if (servicetype.length) {
			servicetypeValue = $(servicetype).val();
			if (!(servicetypeValue === "") && !(servicetypeValue === "REPAIR_SERVICES")) {
				if (service.length) serviceValue = service.val();
				if (workshop.length) workshopValue = workshop.val();
					
				if ((serviceValue === "") && (workshopValue === "")) {
					markFieldError(service);
					markFieldError(workshop);
					return "errorplus";
				}
			}
		}
	}
	return "";
}

function validateAssystABForm() {
	// get form
	f = $("select[name=PersonalVehicleForm_CarClassKey]");
	if (f.length)
		f = f.closest("form");

	// attach form validation
	if (f.is("form")) {
		servicetype = $("select[name=PersonalVehicleForm_ServiceType]");
		milage = $("input[name=PersonalVehicleForm_MilageLastService]");
		regDate = $("input[name=PersonalVehicleForm_DateRegistration]");
		servDate = $("input[name=PersonalVehicleForm_DateLastService]");
		conventional = $("input[name=PersonalVehicleForm_ConventionalService]");
		
		var servicetypeValue = "";
		var milageValue = "";
		var regDateValue = "";
		var servDateValue = "";
		
		var serv_date = ""
		var reg_date = "";
		var today = new Date();
		
	
		
		if (servicetype.length && !(conventional.length && (conventional.val() == "true"))) {
			servicetypeValue = $(servicetype).val();
			if (milage.length) milageValue = milage.val();
			if (regDate.length) regDateValue = regDate.val();
			if (servDate.length) servDateValue = servDate.val();
				
			if (!(servicetypeValue === "") && !(servicetypeValue === "REPAIR_SERVICES")) {
				ret = ""
				removeFieldError(milage);removeFieldError(regDate);removeFieldError(servDate);
				if (milageValue === "") {
					markFieldError(milage);
					ret = "errorab";
				}
				if (regDateValue === "") {
					markFieldError(regDate);
					ret = "errorab";
				} else {
					reg_date=$('input[name=PersonalVehicleForm_DateRegistration]').datepicker('getDate');
					if(reg_date > today)
					{
						markFieldError(regDate);
						ret += "|errordate";
					}
				}
				if (servDateValue === "") {
					markFieldError(servDate);
					ret += "|errorab";
				} else { 
					serv_date=$('input[name=PersonalVehicleForm_DateLastService]').datepicker('getDate');
					if(serv_date > today)
					{
						markFieldError(servDate);
						ret += "|errordate";
					}
				
				}
				return ret;
			}
		}
	}
	return "";
}

function attachServiceTypeChangeEvent() {
	$("#PersonalVehicleForm_ServiceType").change( function() {
		toggleExtraFields(this);
	});
}

function toggleExtraFields(serviceType) {
	conventional = $("#PersonalVehicleForm_ConventionalService");
	if (($(serviceType).val() == "REPAIR_SERVICES") || ($(serviceType).val() == "") || (conventional.val() == "true")) {
		$("div[id=input_PersonalVehicleForm_DateRegistration]").hide();								
		$("div[id=input_PersonalVehicleForm_MilageLastService]").hide();
		$("div[id=input_PersonalVehicleForm_DateLastService]").hide();
		$("div[id=input_PersonalVehicleForm_ServiceCode]").hide();
		$("div[id=input_PersonalVehicleForm_WorkshopCode]").hide();
		
		$("div[id=label_PersonalVehicleForm_DateRegistration]").hide();								
		$("div[id=label_PersonalVehicleForm_MilageLastService]").hide();
		$("div[id=label_PersonalVehicleForm_DateLastService]").hide();
		$("div[id=label_PersonalVehicleForm_ServiceCode]").hide();
		$("div[id=label_PersonalVehicleForm_WorkshopCode]").hide();
		/*
		$("input[name=PersonalVehicleForm_DateRegistration]").val("");								
		$("input[name=PersonalVehicleForm_MilageLastService]").val("");
		$("input[name=PersonalVehicleForm_DateLastService]").val("");
		$("input[name=PersonalVehicleForm_ServiceCode]").val("");
		$("input[name=PersonalVehicleForm_WorkshopCode]").val("");
		*/
	} else if (!((conventional.length) && (conventional == "true"))) {
		$("div[id=input_PersonalVehicleForm_DateRegistration]").show();								
		$("div[id=input_PersonalVehicleForm_MilageLastService]").show();
		$("div[id=input_PersonalVehicleForm_DateLastService]").show();
		$("div[id=input_PersonalVehicleForm_ServiceCode]").show();
		$("div[id=input_PersonalVehicleForm_WorkshopCode]").show();
		
		$("div[id=label_PersonalVehicleForm_DateRegistration]").show();								
		$("div[id=label_PersonalVehicleForm_MilageLastService]").show();
		$("div[id=label_PersonalVehicleForm_DateLastService]").show();
		$("div[id=label_PersonalVehicleForm_ServiceCode]").show();
		$("div[id=label_PersonalVehicleForm_WorkshopCode]").show();
	}
}

/**********************
 * telecash
 **********************/
var tlcurl="";
function setTlcVar(tlcval) {
	tlcurl = tlcval;
}
$(document).ready(function() {
	$('#PaymentInfSubmit').submit(function() {
		if (($('#enbl').val() == 'true') && (tlcurl != "")) {
			var callUrl = tlcurl;
			callUrl = callUrl.replace('0_0', 'DBG_ViewPaymentProvider-LogTelecashParameters');
			var urlParams = "?";
			$.each($('#PaymentInfSubmit').serializeArray(), function(i, field) {
	    		if (field.name != 'enbl') urlParams += 'tlc_' + field.name + '=' + field.value + '&';
			});
			callUrl += urlParams.substring(0,urlParams.length-1);
			$.ajax({url: callUrl,success: function(){},async:false,cache:false});
		}
	});
});

/*******************************************************************************
 * function for adding a hidden parameter to a passed form
 *******************************************************************************/
function addFormParam(formName, paramName, paramValue) {
	jQuery('#' + formName).append('<input type="hidden" name="' + paramName + '" value="' + paramValue + '" />');
}



// sorting of Product filter lists
$(document).ready(function() {
	//$(".SearchFilterSelect").each(function(idx) {
	$("#MBA_CLOSECOLOR_VAR, #MBA_BIKESIZE_VAR").each(function(idx) {
		var selectedOption = $(this).val();
		var options = $(this).find('option');			
		options.sort(function(a,b) {
			if ($(a).val() == "") return -1;
			return (a.text == b.text) ? 0 : (a.text > b.text) ? 1 : -1; //a.text.toUpperCase()
		});
		$(this).empty().append( options );
		$(this).val(selectedOption);
	});
	$("#MBA_CLOSESIZE_VAR").each(function(idx) {
		var sizes = "|XXS|XS|S|M|L|XL|XXL|XXXL|XXXXL|";
		var selectedOption = $(this).val();
		var options = $(this).find('option');
		options.sort(function(a,b) {
			if ($(a).val() == "") return -1;
			if (isNaN(a.text) && isNaN(b.text)) {
				// both not numbers
				var v1 = sizes.indexOf("|" + a.text + "|");
				var v2 = sizes.indexOf("|" + b.text + "|");
				if (v1 < 0) v1 = 999;
				return (v1 == v2) ? 0 : (v1 > v2) ? 1 : -1;
			} else if (isNaN(a.text) && !isNaN(b.text)) {
				// a number, b text
				return 1;
			} else if (isNaN(b.text) && !isNaN(a.text)) {
				// a text, b number
				return -1;
			} else {
				// both numbers
				var v1 = parseFloat(a.text);
				var v2 = parseFloat(b.text);
				return (v1 == v2) ? 0 : (v1 > v2) ? 1 : -1;
			}
		});
		$(this).empty().append( options );
		$(this).val(selectedOption);
	});
	
	$("#variation_colours").each(function(idx) {
		var selectedOption = $(this).val();
		var options = $(this).find('.productColours');	
		options.sort(function(a,b) {			
			return ($(a).attr("title") == $(b).attr("title")) ? 0 : ($(a).attr("title") >$(b).attr("title")) ? 1 : -1; //a.text.toUpperCase()
		});
		//$(options).each(function() {alert($(this).attr("title"));});
		$(this).empty().append( options );
	});
	
	$("#variation_colours_fullscreen").each(function(idx) {
		var selectedOption = $(this).val();
		var options = $(this).find('.fullproductColours');	
		options.sort(function(a,b) {			
			return ($(a).attr("title") == $(b).attr("title")) ? 0 : ($(a).attr("title") >$(b).attr("title")) ? 1 : -1; //a.text.toUpperCase()
		});
		//$(options).each(function() {alert($(this).attr("title"));});
		$(this).empty().append( options );
	});
	
	sortVariationSizes();
	
	$("#variation_framesizes").each(function(idx) {
		var selectedOption = $(this).val();
		var options = $(this).find('.productFrameSizes');	
		options.sort(function(a,b) {			
			return ($(a).html() == $(b).html()) ? 0 : ($(a).html() >$(b).html()) ? 1 : -1; //a.text.toUpperCase()
		});
		$(this).empty().append( options );
	});
	
	$("#MBA_PRICE_VAL").each(function(idx) {
		var selectedOption = $(this).val();
		var options = $(this).find('option');			
		options.sort(function(a,b) {
			if ($(a).val() == "") return -1;
			var v1 = $(a).val(); if (v1.indexOf('-') > 0) v1 = parseFloat(v1.substring(0, v1.indexOf('-')));
			var v2 = $(b).val(); if (v2.indexOf('-') > 0) v2 = parseFloat(v2.substring(0, v2.indexOf('-')));
			return (v1 == v2) ? 0 : (v1 > v2) ? 1 : -1;
		});
		$(this).empty().append( options );
		$(this).val(selectedOption);
	});
});

function sortVariationSizes() {
	$("#variation_sizes").each(function(idx) {
		var sizes = "|XXS|XS|S|M|L|XL|XXL|XXXL|XXXXL|";
		var options = $(this).find('.productSizes');
		options.sort(function(a,b) {
			if (isNaN($(a).html()) && isNaN($(b).html())) {
				// both not numbers
				var v1 = sizes.indexOf("|" + $(a).html() + "|");
				var v2 = sizes.indexOf("|" + $(b).html() + "|");
				if (v1 < 0) v1 = 999;
				return (v1 == v2) ? 0 : (v1 > v2) ? 1 : -1;
			} else if (isNaN($(a).html()) && !isNaN($(b).html())) {
				// a number, b text
				return 1;
			} else if (isNaN($(b).html()) && !isNaN($(a).html())) {
				// a text, b number
				return -1;
			} else {
				// both numbers
				var v1 = parseFloat($(a).html());
				var v2 = parseFloat($(b).html());
				return (v1 == v2) ? 0 : (v1 > v2) ? 1 : -1;
			}
		});		
		$(this).empty().append( options );
	});
}


/*******************************************************************************
 * General functions
 *******************************************************************************/
function goToStep(formid,step) {
	$('<input>').attr({
    	type: 'hidden',
    	id: step,
    	name: step,
    	value: step
	}).appendTo('#' + formid);
	$('#' + formid).submit();
}

/**
* shopping cart change article
* @author Nam Nguyen
*/
function displayChangeItemLayer() {
	$("#layerChangeArticle").show();
}
function hideChangeItemLayer() {
	$("#layerChangeArticle").hide();
}


function refreshSuggestedProdsSlider() {
	if($('.productSuggestion .product').length>5){
		$('.productSuggestion .back').click(function(event){
			// prevent href
			event.preventDefault();
			// remove marking of link wenn clicked
			$(this).blur();
			// move last product to first position
			$('.productSuggestion .scroll .product:last-child').prependTo('.productSuggestion .scroll');
			// remove left padding
			$('.productSuggestion .scroll').css('padding-left','0');
			// animate padding to old value
			$('.productSuggestion .scroll').animate({
				'padding-left': 175
			},500);
		});
		$('.productSuggestion .next').click(function(event){
			// prevent href
			event.preventDefault();
			// remove marking of link wenn clicked
			$(this).blur();
			// animate padding to 0
			$('.productSuggestion .scroll').animate({
				'padding-left': 0
			},500,function(){
			// move first product to last position
			$('.productSuggestion .scroll .product:first-child').appendTo('.productSuggestion .scroll');
			// restore left padding
			$('.productSuggestion .scroll').css('padding-left','175px');
			});
		});
	} else {
		$('.productSuggestion .back').click(function(event) {event.preventDefault();});
		$('.productSuggestion .next').click(function(event){event.preventDefault();});
	}
}

function refreshLastSeenSlider() {
	if($('.lastseenprod .product').length>5){
		$('.lastseenprod .back').click(function(event){
			// prevent href
			event.preventDefault();
			// remove marking of link wenn clicked
			$(this).blur();
			// move last product to first position
			$('.lastseenprod .scroll .product:last-child').prependTo('.lastseenprod .scroll');
			// remove left padding
			$('.lastseenprod .scroll').css('padding-left','0');
			// animate padding to old value
			$('.lastseenprod .scroll').animate({
				'padding-left': 175
			},500);
		});
		$('.lastseenprod .next').click(function(event){
			// prevent href
			event.preventDefault();
			// remove marking of link wenn clicked
			$(this).blur();
			// animate padding to 0
			$('.lastseenprod .scroll').animate({
				'padding-left': 0
			},500,function(){
			// move first product to last position
			$('.lastseenprod .scroll .product:first-child').appendTo('.lastseenprod .scroll');
			// restore left padding
			$('.lastseenprod .scroll').css('padding-left','175px');
			});
		});
	} 
}

function checkElementExistAndVisible(id) {
	return ($('#' + id).length> 0);
}	

function disableAllInputFields(id, disabled) {
	var inputs = $('#' + id + ':input');
	$inputs.each(function() {
        $(this).attr('disabled')=disabled;
    });
	
	var selects = $('#' + id + ':select');
	$selects.each(function() {
        $(this).attr('disabled')=disabled;
    });
	
	var textareas = $('#' + id + ':textarea');
	$textareas.each(function() {
        $(this).attr('disabled')=disabled;
    });
}


function disableAllInputFieldsByRegex(id , disabled) {
	var inputs = $('input[id^="' + id + '"]');
	inputs.each(function() {
		if(disabled == true)
		{
			$(this).attr('disabled', true);
		} else { 
			$(this).removeAttr("disabled");
		}
	});
	
	var selects = $('select[id^="' + id + '"]');
	selects.each(function() {
		if(disabled == true)
		{
			$(this).attr('disabled', true);
		} else { 
			$(this).removeAttr("disabled");
		}
	});
	
	var textareas = $('textarea[id^="' + id + '"]');
	textareas.each(function() {
		if(disabled == true)
		{
			$(this).attr('disabled', true);
		} else { 
			$(this).removeAttr("disabled");
		}
	});
}

$(document).ready(function() {
	/**
	* Add To Basket tooltips
	* 
	*/
	$('#priceBox a.stopicon').hover(function(){
		obj = $('.tooltipstopicon');
		obj.toggle();
	});

	$("#article .modalContent .articleButtonClose").click(function(){
		$("#article .modalWrapper").hide();
	});
});

//execute when page has loaded 
jQuery(window).load( function(){
	// see if image cinema is available
	$('#fullscreenlink').hide();
	//fullscreen link is emporary disabled.
	/*$('.imagechangerimg').each(function() {
		var imgSize = getImgRealSize(this);
		if(imgSize.width >= 1000 || imgSize.height >= 1000)
			$('#fullscreenlink').show();
	});*/	
});

