// JavaScript Document

//livechat popup func
function livechatpop()
 {
   mywindow = window.open ("https://livechat14.volusion.com/livechat.aspx?ID=436687&location=https%3a//www.rosenthalusa-shop.com/admin/tableviewer.asp%3ftable%3dspecials%26isdefaultview%3dtrue&auto=0&cookieGuid=p40cjianjl2ft5qjiy03dxz4&DeptID=0",
  "LiveChat","location=1,status=0,toolbar=0,scrollbars=1,resizable=0,location=0,width=500,height=500");
  mywindow.moveTo(100,100);
 } 

//MyRegistry
            function myregistryminisignup_onclick() {
            var mrwebwidgetcreateaccount = new Object();
            var newScript = document.createElement('script');
            newScript.id = 'mr_scriptAuthentication';
            newScript.type = 'text/javascript';
            var panelLeft='0';
            var panelTop='0';
            var panelBackground='CCCCCC';
            var logopath ='http://www.rosenthalusa-shop.com/v/vspfiles/assets/images/ROS_LOGO_120x50.jpg';
            mrwebwidgetcreateaccount.querystring =  '?HandlerType=3&bgcolor=' + panelBackground + '&logopath=' + logopath + '&left=' + panelLeft + '&top=' + panelTop;
            newScript.src = 'http://www.myregistry.com/WebHandlers/SignupHandler.ashx' + mrwebwidgetcreateaccount.querystring;
            document.body.appendChild(newScript);
        }
            function myregistryminifindafriend_onclick() {
                var mrwebwidgetfindregistry = new Object();
                var newScript = document.createElement('script');
                newScript.id = 'mr_scriptFindRegistry';
                newScript.type = 'text/javascript';
                var panelLeft='428';
                var panelTop='367';
                var panelBackground='CCCCCC';
                var logopath ='http://www.rosenthalusa-shop.com/v/vspfiles/assets/images/ROS_LOGO_120x50.jpg';
                mrwebwidgetfindregistry.querystring =  '?bgcolor=' + panelBackground + '&logopath=' + logopath + '&left=' + panelLeft + '&top=' + panelTop;
                newScript.src = 'http://www.myregistry.com/webwidget/findregistry.aspx' + mrwebwidgetfindregistry.querystring;
                document.body.appendChild(newScript);
            }

		
// Mega Drop Down Navi
$(document).ready(function() {
	//On Hover Over
function megaHoverOver(){
    $(this).find(".sub_mega").stop().fadeTo('fast', 0.8).show(); //Find sub_mega and fade it in
    (function($) {
        //Function to calculate total width of all ul's
        jQuery.fn.calcSubWidth = function() {
            rowWidth = 0;
            //Calculate row
            $(this).find("ul").each(function() { //for each ul...
                rowWidth += $(this).width(); //Add each ul's width together
            });
        };
    })(jQuery); 

    if ( $(this).find(".row").length > 0 ) { //If row exists...

        var biggestRow = 0;	

        $(this).find(".row").each(function() {	//for each row...
            $(this).calcSubWidth(); //Call function to calculate width of all ul's
            //Find biggest row
            if(rowWidth > biggestRow) {
                biggestRow = rowWidth;
            }
        });

        $(this).find(".sub_mega").css({'width' :biggestRow}); //Set width
        $(this).find(".row:last").css({'margin':'0'});  //Kill last row's margin

    } else { //If row does not exist...

        $(this).calcSubWidth();  //Call function to calculate width of all ul's
        $(this).find(".sub_mega").css({'width' : rowWidth}); //Set Width

    }
}
//On Hover Out
function megaHoverOut(){
  $(this).find(".sub_mega").stop().fadeTo('fast', 0, function() { //Fade to 0 opactiy
      $(this).hide();  //after fading, hide it
  });
}

//Set custom configurations
var config = {
     sensitivity: 2, // number = sensitivity threshold (must be 1 or higher)
     interval: 0, // number = milliseconds for onMouseOver polling interval
     over: megaHoverOver, // function = onMouseOver callback (REQUIRED)
     timeout: 50, // number = milliseconds delay before onMouseOut
     out: megaHoverOut // function = onMouseOut callback (REQUIRED)
};

$("ul#topnav_mega li .sub_mega").css({'opacity':'0'}); //Fade sub_mega nav to 0 opacity on default
$("ul#topnav_mega li").hoverIntent(config); //Trigger Hover intent with custom configurations
});

// remove related products headline
$(document).ready(function() {
$("font[class='productnamecolorSMALL colors_productname']").find("b").html("&nbsp;");

// add text to paging
$(".pages_available_text").prepend("go to page: ");
});


// add to cart and details
$(document).ready(function() {


$("td a[class^='productnamecolor']").parent().each(function() { 
var text = $(this).text();
if (text.indexOf("usually") != -1){
	
// details bg

$("td img[src*='-1.jpg']").parents("td[align='center']").each(function() { 
var detailLink = $(this).find("a").attr("href"); 
var ImgDivHeight = $(this).find("img").height();

$(this).prepend('<div class="details-' + detailLink.substr(detailLink.length -20,16) + '" url="' + detailLink + '" style="position:absolute;min-height:70px;height:' + ImgDivHeight + 'px;width:275px;cursor:pointer">&nbsp;</div>');
});

$("div [class^='details-']").mouseenter(function() {
    $(this).fadeTo("slow", 0.7).css("background", "url(http://rosenthalusa-shop.com/v/vspfiles/assets/images/detailsbg.gif) center no-repeat");  
  }).mouseout(function(){
    $(this).css("background", "none");
  });

$("div [class^='details-']").click(function() {  
 window.location = $(this).attr("url"); 
 });


	
	
var linkid = $(this).find(":first").attr("href"); 
var expLink = linkid.split('/');
var num = expLink[expLink.length-1].replace('.htm','');

var itemname = $(this).find(":first").attr("title");
var expItemname = itemname.split(',');
var itemnameclean = expItemname[0] + ", " + expItemname[1]; 
var itemnameclean = itemnameclean.replace('&','and');

var price = $(this).find("font[class^='pricecolor']").text().replace('Price','').replace(/\s/g,'');
var pagelink = "http://www.rosenthalusa-shop.com/v/incart.html?ProductCode="+num+"&ProName="+itemnameclean+"&ProPrice="+price; 

$(this).prepend('<img  src="http://www.rosenthalusa-shop.com/v/vspfiles/templates/rosenthal01/images/buttons/btn_addtocart.gif" id="' + num + '-' + itemnameclean + '-' + price +'" class="btnsend" /><a href="' + pagelink + '" class="fancybox_prod" id="' + num + '"></a><br />');
}
});
});

// fancybox free hsip and product pic zoom
$(document).ready(function(){  
        $("a[href='MailingList_unsubscribe.asp']").addClass("newsl");
        $("a[href='MailingList_unsubscribe.asp']").attr({href:"http://www.rosenthalusa-shop.com/v/vspfiles/assets/newslun.html", style: "background:none !important;"});
	$("a[id='product_photo_zoom_url2']").addClass("fancybox");
	$("a[id='product_photo_zoom_url2']").each(
		function() {
			var link = $(this).attr('href');
			//javascript etc. raus
			link = link.replace("javascript:OpenNewWindow('/PhotoDetails.asp?ShowDESC=N&ProductCode=","/v/vspfiles/photos/");
link = link.replace("' + escape('","");
			link = link.replace("'), 640, 600)","-2.jpg");
			//neuer link zurueck
			$(this).attr('href',link);
		});
	$("a[id='product_photo_zoom_url']").each(
		function() {		
			$(this).attr('href','#');
		});

$("a[onclick^='window.open(\\'/help_FreeShipping.asp']").each(
		function() {
$(this).removeAttr("onclick");			
$(this).addClass("fancybox_fs");
$(this).attr("href", "/help_FreeShipping.asp");
});
});



// fancybox init
$(document).ready(function() {
						   
 $("a.fancybox").fancybox({
'transitionIn'	:	'fade',
'transitionOut'	:	'fade',
'speedIn'	 : 600, 
'speedOut'	 :	200, 
'titlePosition'	:	'inside',
'overlayOpacity' : 0.7,
'overlayColor' : '#333333'
});
						   
						   
 $("a.fancybox_prod").fancybox({
'transitionIn'	:	'fade',
'transitionOut'	:	'fade',
'speedIn'	 : 600, 
'speedOut'	 :	200, 
'titlePosition'	:	'inside',
'overlayOpacity' : 0.7,
'overlayColor' : '#333333',
'type' : 'iframe',
'hideOnContentClick' : 'false'
});

$("a.fancybox_fs").fancybox({
'transitionIn'	:	'fade',
'transitionOut'	:	'fade',
'speedIn'	 : 600, 
'speedOut'	 :	200, 
'titlePosition'	:	'inside',
'overlayOpacity' : 0.7,
'overlayColor' : '#333333',
'type' : 'iframe',
'hideOnContentClick' : 'false'
});

 $("a.fancybox_sa").fancybox({
'transitionIn'	:	'fade',
'transitionOut'	:	'fade',
'speedIn'	 : 600, 
'speedOut'	 :	200, 
'overlayOpacity' : 0.7,
'overlayColor' : '#333333',
'type' : 'iframe',
'hideOnContentClick' : 'false',
'height' : 400,
'width' : 750
});


	
});

// trigger incart
$(document).ready(function() {
$(function() {  
   $("td img.btnsend").click(function() {
  $("#wait").trigger('click');
   var articelcode = $(this).attr("id").split('-')
    
 $.ajax( {
     type: "GET",
     url: "http://www.rosenthalusa-shop.com/shoppingcart.asp?Productcode=" + articelcode[0],
	 context: this,
     success: function() {	$("#"+articelcode[0]).trigger('click')}  
    });

   });
   
  });
});

// turn chat on/off
$(document).ready(function(){
var url = "http://www.rosenthalusa-survey.com/chatswitch/query_jsonp.php"; 

$.getJSON(url+"?callback=?", function(data) {
	$.each(data.rtnhtml,function(i,rtnvals){

	switch(rtnvals.state){
				case '0':
				$("#chat-widget").css("left","-500px");
  				break;
				case '1':
				$("#chat-widget").css("left","-5px");
 				break;
				default:
				$("#chat-widget").css("left","-500px");	
}
});
//$("#results").empty().append(chatStatus).fadeIn("slow");
});

});

// shopping assistant and chat trigger
$(document).ready(function() {
$("#sa-widget").hover(
  function () {
	  $(this).animate({
		  width: '+=30',
  }, 100 );
  }, 
  function () {
    $(this).animate({
		   width: '-=30',
  }, 200 );
  }
);
$("#sa-widget").click(function() {
$(".fancybox_sa").trigger('click');
});

/// chat
$("#chat-widget").hover(
  function () {
	  $(this).animate({
		  width: '+=30',
  }, 100 );
  }, 
  function () {
    $(this).animate({
		   width: '-=30',
  }, 200 );
  }
);
$("#chat-widget").click(function() {
livechatpop();
});
});

// set selected navi
$(document).ready(function() {

if($("a[title='Rosenthal Studio Line']").length){
$(".studioline").css({"background":"url('http://hotel.rosenthal.de/images/bg_nav1.jpg') repeat-x scroll left top #FFFFFF","color":"#000000"});
}

if($("a[title='Rosenthal Classic']").length){
$(".classic").css({"background":"url('http://hotel.rosenthal.de/images/bg_nav1.jpg') repeat-x scroll left top #FFFFFF","color":"#000000"});
}

if($("a[title='Rosenthal meets Versace']").length){
$(".versace").css({"background":"url('http://hotel.rosenthal.de/images/bg_nav1.jpg') repeat-x scroll left top #FFFFFF","color":"#000000"});
}

if($("a[title='Thomas']").length){
$(".thomas").css({"background":"url('http://hotel.rosenthal.de/images/bg_nav1.jpg') repeat-x scroll left top #FFFFFF","color":"#000000"});
}

});
