﻿// JScript File

function ProductsListingFithHeight(){
    
    var maxHeight=0;
    
    var oThumbCells = $('.ProductsListingThumbnailCell')
    oThumbCells.each(function(idx,oItem){
        if(maxHeight<$(oItem).height()) maxHeight=$(oItem).height()
    })    
    oThumbCells.each(function(idx,oItem){
        $(oItem).height(maxHeight)
    })
    
    maxHeight=0;
    var oInfoCells = $('.ProductsListingProductInfo')
    oInfoCells.each(function(idx,oItem){
        if(maxHeight<$(oItem).height()) maxHeight=$(oItem).height()
    })
    oInfoCells.each(function(idx,oItem){
        $(oItem).height(maxHeight)
    })    
}

function ShowAlbum(sAlbumId){
    //Tracking
    var sAction = "Albums.aspx"
    var sData = 'trackalbumid=' + sAlbumId
        
        $.ajax({
				method:'get', 
				url:sAction, 
				data:sData,
				cache: false,
				beforeSend:function(){				    
				},
				complete:function(){					
				},
				success:function(sHTML){                    
				}
        })
    //Show album
    $('#bmvAlbum' + sAlbumId + '').mbGallery({maskBgnd:'#666', maskOpacity:.8});
}

////////////////////////////////////////////////////////
//Survey
////////////////////////////////////////////////////////
function SubmitSurvey(ModuleSurveyID, sAction, NoOptionMessage, ThankMessage){
	var sSurveyId = '#BmvSurvey' + ModuleSurveyID
	var oCheckedOptions=$(sSurveyId + ' input:checked')
	
	if(! oCheckedOptions.length){
	    if(jQuery.trim(NoOptionMessage)!='') alert(NoOptionMessage)
		return false
	}
	
	var sIds = oCheckedOptions.serialize()
	while(sIds.indexOf(oCheckedOptions[0].name + '=')>=0){
		sIds=sIds.replace(oCheckedOptions[0].name + '=','')
	}
	while(sIds.indexOf('&')>=0){
		sIds=sIds.replace('&',',')
	}
	
	$.ajax({
		method		:'get',
		url			:sAction,
		data		:'ModuleSurveyID=' + ModuleSurveyID + '&option=' + sIds,
		beforeSend	:function(){			
		},
		complete	:function(){
		},
		success		:function(sResult){
			var oResultContainer = $(sSurveyId + ' .Result-Container')			
			oResultContainer.html(sResult)
			ShowResult(ModuleSurveyID)
			if(jQuery.trim(ThankMessage)!='') alert(ThankMessage)
		}
	})
}

function ShowSurvey(ModuleSurveyID){
	var sSurveyId = '#BmvSurvey' + ModuleSurveyID
	var btnResult = $(sSurveyId + ' .bmv-Suervey-result-button')
	var oOptionContainer = $(sSurveyId + ' .Option-Container')
	var oResultContainer = $(sSurveyId + ' .Result-Container')
	oResultContainer.css('display','none')
	oOptionContainer.css('display','block')
	btnResult.show()
}

function ShowResult(ModuleSurveyID){
	var sSurveyId = '#BmvSurvey' + ModuleSurveyID
	var btnResult = $(sSurveyId + ' .bmv-Suervey-result-button')
	var oOptionContainer = $('#BmvSurvey' + ModuleSurveyID + ' .Option-Container')
	var oResultContainer = $('#BmvSurvey' + ModuleSurveyID + ' .Result-Container')
	oResultContainer.css('display','block')
	oOptionContainer.css('display','none')
	btnResult.hide()
}
	
function CreateSurvey(ModuleSurveyID,sAction,NoOptionMessage,ThankMessage){    
	var sSurveyId = '#BmvSurvey' + ModuleSurveyID
	var oSurvey = $(sSurveyId)
	if(oSurvey){
		var oOptions = oSurvey.find(':input')
		oOptions.attr('name','BmvSurveyOption' + ModuleSurveyID)
		
		var btnSubmit = $(sSurveyId + ' .bmv-Suervey-submit-button')
		var btnResult = $(sSurveyId + ' .bmv-Suervey-result-button')
		
		var oOptionContainer = $(sSurveyId + ' .Option-Container')
		var oResultContainer = $(sSurveyId + ' .Result-Container')
	
		//Setup submit button		
		if(btnSubmit){
			btnSubmit.click(function(){
				var bShowingResult = (oResultContainer.css("display")=='block')
				if(bShowingResult){
					ShowSurvey(ModuleSurveyID)
				}
				else{
					SubmitSurvey(ModuleSurveyID,sAction,NoOptionMessage,ThankMessage)
				}
				
				return false
			})
		}
		
		//Setup result button
		if(btnResult){
			btnResult.click(function(){
				ShowResult(ModuleSurveyID)				
				return false
				
			})
		}
	
	}	
}
////////////////////////////////////////////////////////
//End of Survey
////////////////////////////////////////////////////////



////////////////////////////////////////////////////////
//Right tab
////////////////////////////////////////////////////////

function CreateRightTab(){
	var oTabLeft=$('#tdLeftTab')
	var oTabRight=$('#tdRightTab')
	
	var oTabLeftContainer=$('#Right_tab_left_item_container')
	var oTabRightContainer=$('#Right_tab_right_item_container')
	
	if(oTabLeft.length && oTabRight.length && oTabLeftContainer.length && oTabRightContainer.length){
		
		oTabRightContainer.hide()
		
		oTabLeft.click(function(){
			if(oTabLeft.attr('class')=='Right_tab_left_item_normal'){
				oTabLeft.attr('class','Right_tab_left_item_selected')
				oTabRight.attr('class','Right_tab_right_item_normal')
				
				//Show tab contant
				oTabRightContainer.hide()
				oTabLeftContainer.show()
				
			}
		})
		
		oTabRight.click(function(){
			if(oTabRight.attr('class')=='Right_tab_right_item_normal'){
				oTabRight.attr('class','Right_tab_right_item_selected')
				oTabLeft.attr('class','Right_tab_left_item_normal')
				
				//Show tab contant
				oTabLeftContainer.hide()
				oTabRightContainer.show()
			}
		})
		
	}
	
}
////////////////////////////////////////////////////////
//End of right tab
////////////////////////////////////////////////////////

$(document).ready(function(){   
    
    InitThirthLevelBox()
    
    CreateRightTab();
    
    $('a img').attr('border','0')
        
    //Home page tab	    
    if(($(".Carousel").length>0)&&($(".PhotoCarousel").length>0)){
        $(function() {
            $(".Carousel").jCarouselLite({
                btnNext: ".next",
                btnPrev: ".prev",
		        visible:6,
		        scroll:6,
		        speed:900
            });
        });
        $(function() {
            $(".PhotoCarousel").jCarouselLite({
                btnNext: ".nextAlbum",
                btnPrev: ".prevAlbum",
		        visible:6,
		        scroll:6,
		        speed:900
            });
        });
        $('#divPhotosTab').hide()
    }
     
})

function clientActiveTabChanged(sender, args) {
    if(sender.get_activeTabIndex()==0){ //Video tab
        $('#divPhotosTab').hide()
        $('#divVideosTab').show()        
    }
    else{   //Photo gallery tab
        $('#divVideosTab').hide()
        $('#divPhotosTab').show()
    }
}

////////////////////////////////////////////////////////////////////////////////
// VERTICAL NAVIGATOR
////////////////////////////////////////////////////////////////////////////////

function TogleThirthLevelBox(oActive,idBox){
	
	if($(oActive).attr('href')=='#'){
		$('.V-nav-level3-box:not(#' + idBox + ')').hide()
		$('#' + idBox + ':hidden').show('fast')
		$('.V-nav-item-selected-level2').removeClass('V-nav-item-selected-level2').addClass('V-nav-item-level2')
		$(oActive).parent().addClass('V-nav-item-selected-level2')
	}	

	return false
}

function InitThirthLevelBox(){	
	$('.V-nav-level3-box').hide()
	$('.V-nav-level3-box-selected').show()
	$('#divVerticalNavigator').css('display','')
}
