/**
  Page load events for Icobest Base
  Author: Michael Lund Rasmussen
  Required files:
	jquery-1.2.1.pack.js
	jquery.scrollTo-min.js
	jquery.scrollShow.js
	
 **/
var Icobest= {
	init: function() {
		this.initJqueryPlugins();
	},
	initJqueryPlugins: function() {
	    var elms = null;
	    if ((elms = $('a.load-local')).length >0) {
	        elms.cluetip({
	            positionBy: 'mouse',
	            showTitle:false,
	            arrows:true,
	            width:110,
                local:true, 
	            dropShadow: true,
                hoverIntent: {    
                              sensitivity:  3,
                              interval:     50,
                              timeout:      0
                             }	            
	            });
	        
	    };
	    if ((elms = $('.js-scrollshow')).length > 0) {
		    $('.js-scrollshow').scrollShow({
			    itemSize:{
				    height:110,
				    width:110
			    },
			    view:'.js-scrollshow-view',
			    content:'.js-scrollshow-images',
			    wrappers:'resize,crop',
			    navigators:'a.js-scrollshow-right,a.js-scrollshow-left',
			    navigationMode:'s',
			    circular:false,
			    setWidth:true,
			    sequentialDistance:-7,
			    start:null
		    });
	    };
	    if ((elms = $('a.attachFeedbackForm')).length > 0) {
	        Icobest.FeedbackHandlingData={}
	        elms.each(
	            function(i) {
	                this.href="javascript:Icobest.FeedbackHandler('"+this.href+"');";
	            }
	        )
	    }
	    
	},
	FeedbackHandler : function (href) {
        if (Icobest.FeedbackHandlingData.theWindow && !Icobest.FeedbackHandlingData.theWindow.closed){
            Icobest.FeedbackHandlingData.theWindow.focus();
        } else {
            Icobest.FeedbackHandlingData.theWindow=window.open(href,'theWindow','top=10, left=10, height=800, width=1000, status=1, menubar=0, resizable=1, scrollbars=1, toolbar=0, location=1, directories=0');
            Icobest.FeedbackHandlingData.timerId=window.setInterval("Icobest.FeedbackCloseHandler()",500);
        }
	},
	FeedbackCloseHandler: function() {
        if (Icobest.FeedbackHandlingData.theWindow.closed) {
            window.clearInterval(Icobest.FeedbackHandlingData.timerId);
            window.open("/Icobest/FeedbackForm.aspx",'theWindow','top=10, left=10, height=800, width=1000, status=1, menubar=0, resizable=1, scrollbars=1, toolbar=0, location=1, directories=0');        
        }
	},
	StopFeedbackCloseHandler: function() {
	    window.clearInterval(Icobest.FeedbackHandlingData.timerId);
	},
	showId : function  (formInputId, idx) {
	    var old=$('#FI' + formInputId).attr('value');
        // unselect the previous selected roof
        //$('#' + formInputId + ' .active').removeClass('active');
        if (old ) {
            if (old != idx.toString()) {
             $('#'+formInputId+ 'Data' + old).addClass("item-data");
             $('#'+formInputId+ 'Item' + old).removeClass('active');
            }
        } 
        $('.item-description').show(); 
        
        // add a class to the selected id 
        $('#'+formInputId+'Item' + idx).addClass('active');
        // set form value
        $('#FI' + formInputId).attr('value', idx);
        $('#'+formInputId+'Data' + idx).removeClass("item-data");
        if (this.reflow) this.reflow();
        
    }

}


$(document).ready(function() {
	Icobest.init();
});
