/* jcarousellite */
/* 
function myajax(this_domain,curr,value1,value2,value3,mycurr1,mycurr2,mycurr3)
{
    $.get(this_domain + '/lib/ajax_jcar_images.php', {curr_id:curr + 1, val1:value1, val2:value2, val3:value3}, 
    function(str) 
    {   
        str = str.split('----------'); 
        $('div.jcar_img_' + mycurr1).html(str[0]);
        $('div.jcar_img_' + mycurr2).html(str[1]); 
        $('div.jcar_img_' + mycurr3).html(str[2]); 
    });   
} */
	
	function myajax(b,c,d,e,f,g,h,i){$.get(b+'/lib/ajax_jcar_images.php',{curr_id:c+1,val1:d,val2:e,val3:f},
	function(a){a=a.split('-----');$('a.jcar_img_'+g).html(a[0]);$('a.jcar_img_'+h).html(a[1]);$('a.jcar_img_'+i).html(a[2])})}
	
	function galleryimages(a_id,cname){$.post(this_domain+'/body/view/ajax_view_images.php',{id:a_id},
	function(str){$("a."+cname).html(str);});}

var m_curr = null;
var m_value1 = null;
var m_value2 = null;
var m_value3 = null;
var m_mycurr1 = null;
var m_mycurr2 = null;
var m_mycurr3 = null;


(function($) {                                          // Compliant with jquery.noConflict()
$.fn.jCarouselLite = function(o) {   
    o = $.extend({
        btnPrev: null,
        btnNext: null,
        btnGo: null,
        mouseWheel: false,
        auto: null,

        speed: 500,
        easing: null,

        vertical: false,
        circular: false,
        visible: 3,
        start: 0,
        scroll: 1,

        beforeStart: null,
        afterEnd: null
    }, o || {});

    return this.each(function() {                           // Returns the element collection. Chainable.

        var running = false, animCss=o.vertical?"top":"left", sizeCss=o.vertical?"height":"width";
        var div = $(this), ul = $("ul", div), tLi = $("li", ul), tl = tLi.size(), v = o.visible;

        if(o.circular) {
			pre_image = tLi.gt(tl-v-1).clone(); pre_image.find("a").removeAttr("rel");
			app_image = tLi.lt(v).clone(); app_image.find("a").removeAttr("rel");
            ul.prepend(pre_image);
			ul.append(app_image);
            o.start += v;
        }
        
        var li = $("li", ul), itemLength = li.size(), curr = o.start;                       
        div.css("visibility", "visible");

        li.css("overflow", "hidden")                        // If the list item size is bigger than required
            .css("float", o.vertical ? "none" : "left")     // Horizontal list
            .children().css("overflow", "hidden");          // If the item within li overflows its size, hide'em

        ul.css("margin", "0")                               // Browsers apply default margin 
            .css("padding", "0")                            // and padding. It is reset here.
            .css("position", "relative")                    // IE BUG - width as min-width
            .css("list-style-type", "none")                 // We dont need any icons representing each list item.
            .css("z-index", "1");                           // IE doesnt respect width. So z-index smaller than div

        div.css("overflow", "hidden")                       // Overflows - works in FF
            .css("position", "relative")                    // position relative and z-index for IE
            .css("z-index", "0")                            // more than ul so that div displays on top of ul
            .css("left", "0px");                            // after creating carousel show it on screen
                
        var liSize = o.vertical ? height(li) : width(li);   // Full li size(incl margin)-Used for animation
        var ulSize = liSize * itemLength;                   // size of full ul(total length, not just for the visible items)
        var divSize = liSize * v;                           // size of entire div(total length for just the visible items)

        li.css("width", li.width())                         // inner li width. this is the box model width
            .css("height", li.height());                    // inner li height. this is the box model height

        ul.css(sizeCss, ulSize+"px")                        // Width of the UL is the full length for all the images
            .css(animCss, -(curr*liSize));                  // Set the starting item

        div.css(sizeCss, divSize+"px");                     // Width of the DIV. length of visible images


    // FA - 10 Mar
        if(parseInt(curr) == 0)
        {
            $(o.btnPrev).css("visibility", "hidden");
        }
    // FA - 10 Mar         
        if(o.btnPrev)                 
            $(o.btnPrev).click(function() {
                var curr1 = 0; 
                var load_image = "<div style='width:100%; text-align:center;'><img border='0' style='margin-top:10px;' src='" + this_domain + "/images/common/loading1.gif' /></div>";   
                if(curr == 3)curr1 = 9;
                if(curr == 0)curr1 = 6;
                if(curr == 9)curr1 = 3;
                if(curr == 6)curr1 = 0;
                var mycurr1 = curr1 + 1;
				showvalue = parseInt(curr) - 1;
                // FA - 10 Mar
                if(showvalue == 0 && !o.circular)
                {
                    $(o.btnPrev).css("visibility", "hidden");
                }
                $(o.btnNext).show();
                // FA - 10 Mar
                if(showvalue <= 0 )
                {
                    showvalue = parseInt(showvalue) + parseInt(tl);
                }
                if($('a.jcar_img_' + mycurr1).html() == "")
                {   
                    $('a.jcar_img_' + mycurr1).html(load_image);
                    var value1  =  $('input.jcar_input_'+ mycurr1).val();
                    
                    var mycurr2 = curr1 + 2;
                    $('a.jcar_img_' + mycurr2).html(load_image);
                    var value2  =  $('input.jcar_input_'+ mycurr2).val();
                    
                    var mycurr3 = curr1 + 3;
                    $('a.jcar_img_' + mycurr3).html(load_image);
                    var value3  =  $('input.jcar_input_'+ mycurr3).val();
                    
                    m_curr   = curr1;
                    m_value1 = value1;
                    m_value2 = value2;
                    m_value3 = value3;
                    m_mycurr1 = mycurr1;
                    m_mycurr2 = mycurr2;
                    m_mycurr3 = mycurr3;
                    setTimeout('myajax(this_domain,m_curr,m_value1,m_value2,m_value3,m_mycurr1,m_mycurr2,m_mycurr3)',1903);
                }
				else if($.trim($("a.aimages_view_"+showvalue).html()) == "" && typeof $("a.aimages_view_"+showvalue).attr("id") !== "undefined")
				{
					c_name = "aimages_view_"+showvalue;
					a_id = $("a.aimages_view_"+showvalue).attr("id");
					//image_id = a_id.replace("a_vimage_","");
					I(a_id).innerHTML = load_image;
					setTimeout("galleryimages(a_id,c_name)",1000);
				}

                
                $("#showcount").html(showvalue+" of "+tl);
               return go(curr-o.scroll); 
            });
        
        if(o.btnNext)
            $(o.btnNext).click(function() { 
           
            var load_image = "<div style='width:100%; text-align:center;'><img border'0' style='margin-top:10px;' src='" + this_domain + "/images/common/loading1.gif' /></div>";   
            var mycurr1 = curr + 1;
			showvalue = parseInt(curr) + 1;
            
            // FA - 10 Mar
            if(showvalue > 0)
            {
                $(o.btnPrev).css("visibility", "visible");
            }
            // FA - 10 Mar
            
        	if(o.btnPrev)
            // FA - 10 Mar
            if(showvalue+3 == tl && !o.circular)
            {
                $(o.btnNext).css("display", "none");
            }
            // FA - 10 Mar
            if(showvalue > tl)
            {
                showvalue = showvalue - tl;
            }
            if($('a.jcar_img_' + mycurr1).html() == "")
            {   
                $('a.jcar_img_' + mycurr1).html(load_image);
                var value1  =  $('input.jcar_input_'+ mycurr1).val();
                
                var mycurr2 = curr + 2;
                $('a.jcar_img_' + mycurr2).html(load_image);
                var value2  =  $('input.jcar_input_'+ mycurr2).val();
                
                var mycurr3 = curr + 3;
                $('a.jcar_img_' + mycurr3).html(load_image);
                var value3  =  $('input.jcar_input_'+ mycurr3).val();
                
                m_curr   = curr;
                m_value1 = value1;
                m_value2 = value2;
                m_value3 = value3;
                m_mycurr1 = mycurr1;
                m_mycurr2 = mycurr2;
                m_mycurr3 = mycurr3;
                setTimeout('myajax(this_domain,m_curr,m_value1,m_value2,m_value3,m_mycurr1,m_mycurr2,m_mycurr3)',1903);     
            }
			else if($.trim($("a.aimages_view_"+showvalue).html()) == ""  && typeof $("a.aimages_view_"+showvalue).attr("id") !== "undefined")
			{
				c_name = "aimages_view_"+showvalue;
				a_id = $("a.aimages_view_"+showvalue).attr("id");
				//image_id = a_id.replace("a_vimage_","");
				I(a_id).innerHTML = load_image;
				setTimeout("galleryimages(a_id,c_name)",1000);
			}
            
            $("#showcount").html(showvalue+" of "+tl);
                 go(curr+o.scroll); 
            
                
                
            });

        if(o.btnGo)
            $.each(o.btnGo, function(i, val) {
                $(val).click(function() {
                    return go(o.circular ? o.visible+i : i);
                });
            });

        if(o.mouseWheel && div.mousewheel)
            div.mousewheel(function(e, d) { 
                return d>0 ? go(curr-o.scroll) : go(curr+o.scroll);
            });

        if(o.auto)
            setInterval(function() { 
                go(curr+o.scroll); 
            }, o.auto+o.speed);

        function vis() {
            return li.gt(curr-1).lt(v);
        };  

        function go(to) {
            if(!running) {
/*                   alert(liSize + " " + width(li));*/
                   
                if(o.beforeStart)
                    o.beforeStart.call(this, vis());

                if(o.circular) {            // If circular we are in first or last, then goto the other end
                    if(to<=o.start-v-1) {           // If first, then goto last
                        ul.css(animCss, -((itemLength-(v*2))*liSize)+"px");  
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be lesser depending on the number of elements. 
                        curr = to==o.start-v-1 ? itemLength-(v*2)-1 : itemLength-(v*2)-o.scroll;
                    } else if(to>=itemLength-v+1) { // If last, then goto first
                        ul.css(animCss, -( (v) * liSize ) + "px" );
                        // If "scroll" > 1, then the "to" might not be equal to the condition; it can be greater depending on the number of elements. 
                        curr = to==itemLength-v+1 ? v+1 : v+o.scroll;
                    } else curr = to;
                } else {                    // If non-circular and to points to first or last, we just return.
                    if(to<0 || to>itemLength-v) return;
                    else curr = to;
                }                           // If neither overrides it, the curr will still be "to" and we can proceed.

                running = true;
                
                ul.animate(
                    
                    animCss == "left" ? {left: -(curr*width(li)) } : { top: -(curr*liSize) } , o.speed, o.easing,
                    function() {
                        if(o.afterEnd)
                            o.afterEnd.call(this, vis());
                        running = false;
                    }
                );
                // Disable buttons when the carousel reaches the last/first, and enable when not
                if(!o.circular) {
                    $(o.btnPrev + "," + o.btnNext).removeClass("disabled");
                    $( (curr-o.scroll<0 && o.btnPrev) 
                        || 
                       (curr+o.scroll > itemLength-v && o.btnNext)
                        ||
                       []
                     ).addClass("disabled");
                }

            }
            return false;
        };
    });
};



function css(el, prop) {
    return parseInt($.css(el[0], prop)) || 0;
};
function width(el) {
    return  el[0].offsetWidth + css(el, 'marginLeft') + css(el, 'marginRight');
};
function height(el) {
    return el[0].offsetHeight + css(el, 'marginTop') + css(el, 'marginBottom');
};
})(jQuery);





/* support */
(function(c){c.each(["eq","lt","gt","contains"],function(i,n){c.fn[n]=function(a,b){return this.filter(":"+n+"("+a+")",b)}});c.fn.evalScripts=function(){};c.fn.loadIfModified=function(){var a=c.ajaxSettings.ifModified;c.ajaxSettings.ifModified=true;var b=c.fn.load.apply(this,arguments);c.ajaxSettings.ifModified=a;return b};c.getIfModified=function(){var a=c.ajaxSettings.ifModified;c.ajaxSettings.ifModified=true;var b=c.get.apply(c,arguments);c.ajaxSettings.ifModified=a;return b};c.ajaxTimeout=function(a){c.ajaxSettings.timeout=a}})(jQuery);


/* preview */
function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}
var initialize = false;
var ContentInfo = '';
var ToolTip;
var pos = new Array(2);
pos[0] = 0;
pos[1] = 0;

var topColor = "#4F4F4F";
var subColor = "#EEEEEE";

function loadfunc() 
{
    ToolTip = document.getElementById("ToolTip");

}           
function overhere(e,x,y)
{     
	if(!x)x = 15;
	if(!y)y=15;
	
    if(initialize) 
    {
        MoveToolTip(truebody().scrollLeft + e.clientX + x, truebody().scrollTop + e.clientY + y);
    }
}

function display_preview(pos_top, pos_left)
{     
    if(initialize) 
    {
        MoveToolTip(pos_left, pos_top);
    }
}
   
function Activate() 
{ 
	/* loadfunc(); */
    MoveToolTip(pos[0] , pos[1]);  
    ToolTip.style.visibility = "visible";
    initialize = true;
}

function deActivate() 
{ 
	MoveToolTip(0,0);
    ToolTip.style.visibility = "hidden";
    initialize = false;
}

function MoveToolTip(x, y) 
{
    ToolTip.style.left = x + 'px';
    ToolTip.style.top = y + 'px';
}

function ReplaceContent() 
{
    ToolTip.innerHTML = ContentInfo;
}

function EnterContent(layerName, TTitle, TContent, width)
{
    if(!width)width = 250;
    ContentInfo = '<table border="0" width="'+width+'" cellspacing="0" cellpadding="0">'+
    '<tr><td width="100%" bgcolor="#4F4F4F">'+
    '<table border="0" width="100%" cellspacing="2" cellpadding="0">'+
    '<tr><td width="100%" bgcolor='+topColor+'>'+
    '<table border="0" width="100%" cellspacing="0" cellpadding="0" align="center">'+
    '<tr><td width="100%">'+
    '<font class="tooltiptitle">'+TTitle+'</font>'+
    '</td></tr>'+
    '</table>'+
    '</td></tr>'+
    '<tr><td width="100%" bgcolor='+subColor+'>'+
    '<table border="0" width="100%" cellpadding="0" cellspacing="2" align="center">'+
    '<tr><td width="100%">'+
    '<font class="tooltipcontent">'+TContent+'</font>'+
    '</td></tr>'+
    '</table>'+
    '</td></tr>'+
    '</table>'+
    '</td></tr>'+
    '</table>';
    ReplaceContent();
}

