/********************************************************************/
/***                                                              ***/
/*				ProductDetail Main Controller						*/
/***                                                              ***/
/********************************************************************/
jQuery(document).ready(function() {
engage();
});
/****************************************************************/
/*             engage                                           */
/****************************************************************/
/* setup and event hooking */
function engage() {
// get product parameter 
var articleId = jQuery('#articlePrimaryKey').val();
var productSku = jQuery('#productSku').val();
var pathMain = jQuery('#pathMain').val();
var sendToFriendUrl = jQuery('#sendToFriendUrl').val();
// event hooking
jQuery('#buttonPrint').click(function() { printPage() });
jQuery('#buttonAddCart').click(function(){addToCart(articleId, productSku, pathMain)});
jQuery('#buttonAddToWishList').click(function(){addToWish(articleId, productSku, pathMain)});
jQuery('#buttonSendToFriend').click(function(){sendToFriend(sendToFriendUrl)});
 	jQuery('#product_extra_1 h3').click(function(){showHideExtra(1)});
 	jQuery('#product_extra_2 h3').click(function(){showHideExtra(2)});
 	jQuery('#product_extra_3 h3').click(function(){showHideExtra(3)});
 	jQuery('#product_designer_link a').click(showDesigner, function(){});
 	jQuery('#product_video_link a').click(showVideo, function(){});
jQuery('#single_image_link a').click(function(){showSingleImage()});
 	jQuery('#gall1 a').click(function(){showGallery(1)});
 	jQuery('#gall2 a').click(function(){showGallery(2)});
 	jQuery('#gall3 a').click(function(){showGallery(3)});
 	jQuery('#gall4 a').click(function(){showGallery(4)});
 	
 	jQuery('#designer_close').click(function(){hideDesigner()});
}//engage
/****************************************************************/
/*             addToCart                                        */
/****************************************************************/
/* add the article to cart */
addToCart = function(articleId, productSku, pathMain)
{
jQuery.ajax(
{
url: pathMain + '/ext/dettaglio_prodotto/add_to_cart_ajax',
data: {
productSku:productSku,
articleId:articleId
},
dataType: 'json',
cache: false,
type: 'get',
success: function(json) {
forceReloadCart();
pageTracker._trackEvent('Cart', 'Add', productSku);
}
}
);	
}//addToCart
/****************************************************************/
/*             addToWish                                        */
/****************************************************************/
/* add the article to wish list */
addToWish = function(articleId, productSku, pathMain)
{
jQuery.ajax(
{
url: pathMain + '/ext/dettaglio_prodotto/add_to_wishlist_ajax',
data: {
productSku:productSku,
articleId:articleId
},
dataType: 'json',
cache: false,
type: 'get',
success: function(json) {
forceReloadWish();
 pageTracker._trackEvent('WishList', 'Add', productSku);
}
}
);
}//addToCary
/****************************************************************/
/*             sendToFriend                                     */
/****************************************************************/
/* add the article to wish list */
sendToFriend = function(url)
{
location.href=url;
}//sendToFriend
/****************************************************************/
/*             showHideExtra                                    */
/****************************************************************/
/* show or hide detail extra div */
showHideExtra = function(n) {
jQuery('#product_extra_text_'+n).toggle(200);
if (jQuery('#product_extra_'+n).is('.product_extra_open'))
jQuery('#product_extra_'+n).removeClass('product_extra_open').addClass('product_extra_close');
else
jQuery('#product_extra_'+n).removeClass('product_extra_close').addClass('product_extra_open');
}//showHideExtra
/****************************************************************/
/*             showDesigner                                     */
/****************************************************************/
/* show deigner image div */
showDesigner = function() {
jQuery('.product_main_image:visible').fadeOut(200, function() { jQuery('.product_designer_image').fadeIn(200); });
jQuery('.product_main_video:visible').fadeOut(200, function() { jQuery('.product_designer_image').fadeIn(200); });
jQuery('.thumbGallery li').removeClass("product_gallery_on").addClass("product_gallery_off");
}//showDesigner
/****************************************************************/
/*             hideDesigner                                     */
/****************************************************************/
/* hide deigner image div and show previous image */
hideDesigner = function() {
jQuery('.product_designer_image').fadeOut(200, function() { jQuery('.product_main_image').fadeIn(200); });
for (var i=1; i<5; i++) {
if (jQuery('#imageGallery'+i).is(":visible")) {
jQuery('#gall'+i).removeClass("product_gallery_off").addClass("product_gallery_on");
}
}
}//hideDesigner
/****************************************************************/
/*             showVideo                                        */
/****************************************************************/
/* show video div */
showVideo = function() {
jQuery('.product_main_image:visible').fadeOut(200, function() { jQuery('.product_main_video').fadeIn(200); });
jQuery('.product_designer_image:visible').fadeOut(200, function() { jQuery('.product_main_video').fadeIn(200); });
jQuery('.thumbGallery li').removeClass("product_gallery_on").addClass("product_gallery_off");
}//showVideo
/****************************************************************/
/*             showGallery                                      */
/****************************************************************/
/* hide the visible div and show the image passed by parameter */
showGallery = function(n) {
jQuery('.thumbGallery li').removeClass("product_gallery_on").addClass("product_gallery_off");
jQuery('#gall'+n).removeClass("product_gallery_off").addClass("product_gallery_on");
jQuery('.product_main_image:visible').show('fast', function() { showImage(n); } );
jQuery('.product_designer_image:visible').fadeOut(200, function() { showImage(n); } );
jQuery('.product_main_video:visible').fadeOut(200, function() { showImage(n); } );
}//showGallery
showImage = function(n) {
jQuery('#current_image').html(n);
jQuery('.product_main_image img:visible').fadeOut(200, function() {
jQuery('#imageGallery'+n).fadeIn(200, function() { jQuery('.product_main_image').fadeIn(200); } );
});
}//showImage
showSingleImage = function() {
jQuery('.product_designer_image:visible').fadeOut(200, function() {jQuery('.product_main_image').fadeIn(200);});
jQuery('.product_main_video:visible').fadeOut(200, function() {jQuery('.product_main_image').fadeIn(200);});
}//showSingleImage
/****************************************************************/
/*             printPage                                        */
/****************************************************************/
/* hide the visible div and show the image passed by parameter */
printPage = function() {
jQuery('.product_extra_close div').show();
jQuery('.product_extra_close').removeClass('product_extra_close').addClass('product_extra_open');
jPrintArea(".detail");
}//printPage
/****************************************************************/
/*             jPrintArea                                       */
/****************************************************************/
/* print the area in the selector passed by parameter */
jPrintArea=function(el) {
var iframe=document.createElement('IFRAME');
var doc=null;
jQuery(iframe).attr('style','position:absolute;width:0px;height:0px;left:-500px;top:-500px;');
jQuery(iframe).attr('id','printIFrame');
document.body.appendChild(iframe);
doc=iframe.contentWindow.document;
var links=window.document.getElementsByTagName('link');
for(var i=0;i<links.length;i++)
if(links[i].rel.toLowerCase()=='stylesheet')
doc.write('<link type="text/css" rel="stylesheet" href="'+links[i].href+'"></link>');
doc.write('<style>.detail { width:100%;  font-size: 12px; } .product_category, #back { display: none; } .product_extra_open { width: 100%; } .detail .product_description {width:450px;} .detail .product_attribute { width: 150px; } </style>');
doc.write('<p style="text-align:right;"><img src="/image/layout_set_logo?img_id=18501&t=1242047917893" border=0 /></p><hr style="border:0px;"/>');
doc.write('<div class="'+jQuery(el).attr("class")+'">'+jQuery(el).html()+'</div>');
setTimeout(function() { printNow(doc,iframe); }, 100);
}
function printNow(doc, iframe) {
doc.close();
iframe.contentWindow.focus();
iframe.contentWindow.print();
}