// JavaScript Document
jQuery(document).ready(function() {
	jQuery('#mycarousel, #mycarousel1').jcarousel();
	if (jQuery("select").length > 0) {
		jQuery("#Navigation>li>ul").bgiframe({ opacity: false, src: '' });
	}
});

jQuery(document).ready(function() {
	jQuery("#linkNaviMenu>li>ul").hide();
	jQuery("#linkNaviMenu>li").hover(
		function() {
			jQuery(this).find(">ul").stop().height('auto').slideDown("fast");
		},
		function() {
			jQuery(this).find(">ul").stop().slideUp("fast");
		}
	);
});

/* Correct hspace and vspace assigned by hybris wysiwyg editor */
jQuery(document).ready(function() {
	jQuery("img[hspace]").each(function() {
		var hspace = jQuery(this).attr("hspace");
		jQuery(this).css("margin-left", hspace + "px");
		jQuery(this).css("margin-right", hspace + "px");
	});

	jQuery("img[hspace]").each(function() {
		var vspace = jQuery(this).attr("vspace");
		jQuery(this).css("margin-top", vspace + "px");
		jQuery(this).css("margin-bottom", vspace + "px");
	});
});

jQuery(document).ready(function() {
	jQuery("#destination").scrollTo(0);

	if (!jQuery.browser.msie) {
		jQuery("#destination").mouseleave(function() {
			jQuery("#destination").scrollTo(0);
		});
	}
});

jQuery(document).ready(function() {
	jQuery("#destination>li>a").attr("href", function() {
		return this + window.location.search;
	});
});

function openDivAsFacebox(faceboxDiv) {
	jQuery.facebox({ div: "#"+faceboxDiv });
}

jQuery(document).ready(function() {
	var counter = 0;
	jQuery("a[rel='gigasetMovieLink']").each(function() {
		counter++;
		
		var href = jQuery(this).attr("href");
		var parts = href.split("|");

		var movie = escape(parts[0]);
		var width = escape(parts[1]);
		var height = escape(parts[2]);
		var link = escape(parts[3]);

		var iframeLink = flashLink + "?";
		iframeLink = iframeLink + "file=" + movie + "&width=" + width + "&height=" + height + "&link=" + link;

		jQuery("#flashPlaceholder").append(
				'<div id="flashPopup' + counter + '" style="display:none;">'
				+ '<iframe id="flashIframe' + counter + '" name="flashIframe' + counter + '" scrolling="no" height="' + height + '" width="' + width + '" frameborder="0" marginwidth="0" marginheight="0" src="' + iframeLink + '">'
				+ '</iframe>'
				+ '</div>'
			);
		jQuery(this).removeAttr("href");
		jQuery(this).attr("rev", "movie" + counter);
		jQuery(this).attr("id", "movieLink" + counter);

		jQuery("#movieLink" + counter).click(function() {
			var movieId = jQuery(this).attr("rev").substring("movie".length);
			openDivAsFacebox('flashPopup' + movieId);
			jQuery(document).bind('close.facebox', function() {
				window.frames["flashIframe" + movieId].removeFlash();
			});
		});
	});

	if (jQuery("a[rel='gigasetMovieLink']").size() > 0) {
		jQuery(document).bind('close.facebox', function() {
			jQuery.unblockUI();
		});
		jQuery(document).bind('loading.facebox', function() {
			jQuery.blockUI({ message: null });
		});
	}
});

jQuery("div.blockUI").live('click', function() {
	jQuery(document).trigger('close.facebox');
});
