/*********************************************************************
'***    Program: centerImageInBlock(imgId, intMaxHeight)
'***
'***    Function: makes image to be vertically centered in block
'***
'***    Parameters: 
'***		imgId [id]* - jQuery image id
'***		intMaxHeight [int]*  - height of the block where image located
'***
'***    Returns: Void
'***    Remarks: none
'***
'***    Created by: sergeyh
'***    Changed by: 
'***    Last change: 03/11/2011
'*********************************************************************/
function centerImageInBlock(imgId, intMaxHeight){
    intMaxHeight = parseInt(intMaxHeight);
    if(isNaN(intMaxHeight) || intMaxHeight <= 0)
        return;
    
    objImg = jQuery(imgId);
    if(!objImg)
        return;
    
    var intHeight = objImg.height(); // get image height
    if(intHeight > 0 && intHeight < intMaxHeight){
        var intMargin = Math.round((intMaxHeight - intHeight) / 2);
        objImg.css("margin-top", intMargin + "px")
    }
}
/*********************************************************************
'***    Program: showEnlargedImgInBlock(imgId, resultCntId, intHeight)
'***
'***    Function: gets image by given id and shows it with original sizes in result block (
'***
'***    Parameters: 
'***		imgId [id]* - jQuery image id
'***		resultCntId [id]  - block where enlarged image will be set
'***        intHeight [int] - height of the block where image will be located (needs to make it vertically centered)
'***        intMaxImgWidth [int] - resize image to fit block width
'***
'***    Returns: Void
'***    Remarks: supposes that given image resized with attribute width (but originally it has greater resolution)
'***
'***    Created by: sergeyh
'***    Changed by: 
'***    Last change: 03/11/2011
'*********************************************************************/
function showEnlargedImgInBlock(imgId, resultCntId, intHeight, intMaxImgWidth){
    if(!resultCntId)
        resultCntId = "#productPreview";
    
    var strStyles = "";
    if(intMaxImgWidth)
        strStyles = ' width="' + intMaxImgWidth + '"';
    
    var objImg = jQuery(imgId);
    var imgSrc = objImg.attr("src");
    var imgTitle = objImg.attr("alt");
    
    var imgHtml = '<img src="' + imgSrc + '" alt="' + imgTitle + '" title="' + imgTitle + '" id="previewImg"' + strStyles +'/>';
    
    jQuery(resultCntId).html(imgHtml);
    
    if(intHeight)
        centerImageInBlock("#previewImg", intHeight);
}

/*********************************************************************
'***    Program: showShadowboxVideo(url, strTitle, intWidth, intHeight)
'***
'***    Function: shows popup video
'***
'***    Parameters: 
'***		url [str]* - url to video file
'***		strTitle [str]*  - title of the popup window
'***        intWidth [int]* - width of the video window
'***        intHeight [int]* - height of the video window
'***
'***    Returns: Void
'***    Remarks: shadowbox plugin should be already connected
'***
'***    Created by: sergeyh
'***    Changed by: 
'***    Last change: 03/11/2011
'*********************************************************************/
function showShadowboxVideo(url, strTitle, intWidth, intHeight){
    intWidth = parseInt(intWidth);
    intHeight = parseInt(intHeight);
    if(isNaN(intWidth) || isNaN(intHeight) || intWidth <= 0 || intHeight <= 0)
        return;
    
    Shadowbox.init({
        skipSetup: true // let's skip the automatic setup because we don't have any properly configured link elements on the page
    });
    Shadowbox.open({
        content: url,
        title: strTitle,
        player: "swf",
        width: intWidth,
        height: intHeight
    });
}
