jQuery(document).ready(function($){

	if (jQuery("#content .wide .products").size() > 1) {
		jQuery("#content .products").each(function(counter) {
			if ((counter != 4) && (counter != 13)) {
				jQuery(this).show();
			}
		});
	}

	if(initFunction.length) {
		for (var i = 0; i < initFunction.length; i++) {
			eval(initFunction[i]+"();");
		}
	}

	jQuery(".teaser .linklist a").addClass("linkpfeil");

	if (window.contentinit) { contentinit(); }

	jQuery('#mycarousel').jcarousel({
		vertical: false
	});
	
    jQuery('#myrelatedcarousel').jcarousel({
		vertical: false
	});

    jQuery('#mydesignscarousel').jcarousel({
		vertical: false
	});

    jQuery('#mylittlecarousel').jcarousel({
		vertical: true
	});
	
	jQuery(".carouselH").jcarousel({
		vertical: false
	});

	jQuery(".carouselV").jcarousel({
		vertical: true
	});

	jQuery(function() {
		jQuery('#gallery a.lightbox,.carouselH a.lightbox').lightBox({
			overlayBgColor: '#2E0F24',
			imageLoading: '/Content.Node/images/lightbox-ico-loading.gif',
			imageBtnClose: '/Content.Node/images/lightbox-btn-close.gif',
			imageBtnPrev: '/Content.Node/images/lightbox-btn-prev.gif',
			imageBtnNext: '/Content.Node/images/lightbox-btn-next.gif'
		});
	});

	jQuery(".inspiration-detail .zoomFirstImage").css("display","inline");
	jQuery(".inspiration-detail .zoomFirstImage").click(function() {
		jQuery("#gallery .w274w364 a").click();
	});

	jQuery(".deactivate").click(function() {
		tb_remove();
	});

    if(jQuery.browser.msie) {
		jQuery(".two-col hr").before("<img class='hr' width='336px' height='2px' src='/Content.Node/images/gen-bg-box1-seperator.png' />").remove();
		jQuery(".teaser hr").before("<img class='hr' width='194px' height='2px' src='/Content.Node/images/right-seperator.png' />").remove();
		jQuery(".inspiration-howto .maxi hr").before("<img class='hr' width='286px' height='2px' src='/Content.Node/images/gen-bg-box1-seperator-286px.png' />").remove();
	
		jQuery(".teaser .linklist a").prepend("<img src='/Content.Node/images/gen-ico-textlink-pfeil.gif' alt='' /> ");
		jQuery(".back").prepend("<img src='/Content.Node/images/gen-ico-textlink-pfeil-left.gif' alt='' /> ");		
		jQuery(".bottomlink").prepend("<img src='/Content.Node/images/gen-ico-textlink-pfeil.gif' alt='' />&nbsp;");
		jQuery("#filter-inspirations .linkpfeil,#filter-downloads .linkpfeil,#footer a,.center .linkpfeil").prepend("<img src='/Content.Node/images/gen-ico-textlink-pfeil.gif' alt='' /> ");

		
		if (jQuery.browser.version < 7) {

			jQuery(".link_img a img+img+img").css("left","1px");
			jQuery(".link_img a img+img+img").css("top","1px");
			
			
			jQuery.ifixpng('/Content.Node/images/ie6pixel.gif');

			if (jQuery("#wish_link").size() == 0) {
				jQuery("img[@src$=.png]").ifixpng();
			} else {
				jQuery(".teaser img[@src$=.png]").ifixpng();
			}
			
			jQuery(".carouselV li a img[@alt=hover],.jcarousel-skin-smallvertical li a img[@alt=hover]").attr("src","/Content.Node/images/ie6pixel.gif");
			jQuery(".carouselV li a img.list-entry-image,.jcarousel-skin-smallvertical li a img.content").css("height","50px");


			var hover = null;
			jQuery("img.content").mouseover(
		      function () {
				hover = window.setTimeout("unHoverImages()", 100);
				jQuery(this).prev().css('z-Index','10');
			  }
		    );

		    jQuery("img.hover").mouseover(
				function() {
					window.clearTimeout(hover);
				}
			);
			jQuery("img.hover").mouseout(
		      function () {
				window.clearTimeout(hover);
				jQuery(this).css('z-Index','1');
		      }
		    );
			
						
		}
	}

	jQuery("#imageflow #loading").empty();
	jQuery("#imageflow #loading").prepend("<b>Loading images</b><br/><img src='/Content.Node/images/LoadingImage.gif' alt='loading' />")

	//new imageflow init
	var imageflowInstance = new ImageFlow();
	imageflowInstance.init({
		ImageFlowID: 'imageflow-new',
		reflections: false,
		aspectRatio: 1.25,
		imagesHeight: 0.5,
		imageFocusM: 1.4,
		startID: 3
	});

	if (jQuery.browser.safari) {
	} else if ((jQuery.browser.msie) && (jQuery.browser.version < 7)) {
		jQuery('#accordion').accordion({ 
			active: false, 
			header: 'a.accordion-title',
			alwaysOpen: false, 
			autoHeight: false,
			animated: false
		});
		jQuery("#accordion").accordion("activate", 0)

	} else {
		jQuery('#accordion').accordion({ 
			active: false, 
			header: 'a.accordion-title',
			alwaysOpen: false, 
			autoHeight: false
		});
		jQuery("#accordion").accordion("activate", 0)
	}
	
	jQuery('a').focus(function() {
		jQuery(this).blur();
	});
	
	
	jQuery('.cluetip').cluetip({
		splitTitle: '|',
		arrows:true,
		positionBy:'fixed',
		width:100,
		dropShadow:false
	});

	jQuery(".flashcontrols .play").click(function(){
		playmovie();
	});
	jQuery(".flashcontrols .stop").click(function(){
		stopmovie();
	});
	jQuery(".flashcontrols .replay").click(function() {
		go(0);
		playmovie();
	});

	jQuery(".jQueryContent").css("left","0px");

	jQuery("#search").submit(function() {
		if (jQuery("#search input").val() == "Search") {
			jQuery("#search input").val("");
		}
	});
	jQuery("#search input").focus(function() {
		if (jQuery("#search input").val() == "Search") {
			jQuery("#search input").val("");
		}
	});
	jQuery("#search input").blur(function() {
		if (jQuery("#search input").val() == "") {
			jQuery("#search input").val("Search");
		}
	});
	jQuery("#search input").val("Search");
	
	if ($('#homeslides').size()) {
		$('#homeslides').cycle({ 
		    fx:     'scrollLeft', 
		    speed:  1200, 
		    timeout: 5000
		});
	}

	if ($('#gluinghomeslides').size()) {
		$('#gluinghomeslides').cycle({ 
		    fx:     'scrollLeft', 
		    speed:  1200, 
		    timeout: 5000
		});
	}

	$('#surveymodalwindow').jqm({
		modal: true,
		trigger: 'a.surveylink',
		target: '#jqmContent',
		onShow: loadInIframeModal,
		overlay: 70
	});

	if ($('div.online-stores a').size()) {
		$('div.online-stores a').click(function() { return shoppingConfirmation(); });
	}
	
	// Init Store-Selector Dropdowns
	if ($('#online-store-dropdown').size()) {
		$('#online-store-dropdown').bind('change', function() {
			if ($(this).find('option:selected').val() != "0") {
				if (shoppingConfirmation()) {
					window.open("/Content.Node/Storeframe.en.php?pid=" + $(this).find('option:selected').val());
				}
			}
		});
	}
	if ($('#offline-store-dropdown').size()) {
		$('#offline-store-dropdown').bind('change', function() {
			if ($(this).find('option:selected').val() != "0") {
				document.location.href = "/Content.Node/additional/Shop-Details.en.php?pid=" + $(this).find('option:selected').val();
			}
		});
	}

	// Init itemlist on shopping frameset
	if ($('#itemlist-carousel').size()) {
		$('#itemlist-carousel').jcarousel();
		$('#itemlist-carousel li').click(function() {
			$('#itemlist-carousel li').removeClass('selected');
			$(this).addClass('selected');
			
			window.parent.shopsite.location.href = $(this).attr('rel');
			$('#list-close').attr('href', $(this).attr('rel'));
		});
		
		// Simulate click on first element to initially select it
		$($('#itemlist-carousel li').get(0)).click();
	}
	
	// Initialize google maps on store detail page
	if (window.initStoreMap && $('#store-map-canvas').size()) {
		initStoreMap();
	}
	
	// Init help Link
	if ($('#shoppinglist #footer p.help a.helpLink').size()) {
		$('#shoppinglist #footer p.help a.helpLink').unbind('click');
		$('#shoppinglist #footer p.help a.helpLink').bind('click', function() {
			openShoppingListHelp();
		});
		
		// Initially show help window once
		//openShoppingListHelp();
	}
});

var loadInIframeModal = function(hash) {
	var $trigger = $(hash.t);
	var $modal = $(hash.w);
	var myUrl = $trigger.attr('href');
	var myTitle = $trigger.attr('title');
	var $modalContent = $('iframe', $modal);
	
	$modalContent.html('').attr('src', myUrl);
	$modal.jqmShow();
	$modal.show();

	// Little hack
	$modalContent.get(0).onload = function() {
		$modalContent.css('height','427px');
	};
}

var movieName = "flashmovie";

function thisMovie(movieName) {
  if (navigator.appName.indexOf ("Microsoft") !=-1) {
    return window[movieName]
  }	else {
    return document[movieName]
  }
}

function movieIsLoaded (theMovie) {
  if (typeof(theMovie) != "undefined") {
    return theMovie.PercentLoaded() == 100;
  } else {
    return false;
  }
}

function playmovie() {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).Play();
  }
}

function stopmovie() {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).StopPlay();
  }
}


function go(theFrame) {
  if (movieIsLoaded(thisMovie(movieName))) {
    thisMovie(movieName).GotoFrame(theFrame);
  }
}

function unHoverImages() {
	jQuery("img.hover").css('z-Index','1');
}

function openShoppingListHelp() {
	var windowWidth = 600;
	var windowHeight = 208;
	var windowLeft = screen.width / 2 - windowWidth / 2;
	var windowTop = screen.height / 2 - windowHeight / 2;
	shoppinglistHelpWindow = window.open('/Content.Node/Shoppinglist-Help.en.php', "ShoppingListHelp", "width="+windowWidth+", height="+windowHeight+", top="+windowTop+", left="+windowLeft+", location=no, menubar=no, resizable=no, scrollbars=no, status=no, toolbar=no");
}

function shoppingConfirmation() {
	return confirm("You are leaving the CREATE YOUR STYLE with SWAROVSKI ELEMENTS Website.\n\nThe content of the following pages is in the responsibility of the stores.\n\nEnjoy shopping.");
}
