var count = "";
var newid = "";
var name = "";

function ClientClick(idImage, url) {
    document.getElementById(idImage).src = url;
    //'imgCircuit'
    return false;
}


function slideExample2(elementId, headerId, headerElement) {
    count = document.getElementById('HF').value;


    ////            var element = document.getElementById(elementId);
    ////            if (element.up == null || element.down) {               
    ////                animate(elementId, 20, 0, 0, 400, 400, null);
    ////                element.up = true;
    ////                element.down = false;
    ////                headerElement.innerHTML = '&gt;<br />&gt;<br />&gt;';                        
    ////            }
    ////            else {                
    ////                animate(elementId, 20, 0, 500, 400, 400, null);
    ////                element.down = true;
    ////                element.up = false;
    ////                headerElement.innerHTML = '&lt;<br />&lt;<br />&lt;';
    ////            }
    if (headerId == 'exampleHeader2') {

        if (count == '3') {
            document.getElementById('HF').value = '0';
        }

        if (document.getElementById('HF').value == '0') {
            animate(elementId, 20, 0, 0, 300, 250, null);
            document.getElementById('DV1').innerHTML = "<br/><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='320' height='180' id='Object2' name='single1'> <param name='movie' value='player.swf'/> <param name='allowfullscreen' value='true'/><param name='allowscriptaccess' value='always'/><param name='wmode' value='transparent'/> <param name='flashvars' value='file=VPB LTC3108.flv&image=video_img.jpg'/><embed src='player.swf' width='270' height='180' allowscriptaccess='always' allowfullscreen='true'flashvars='file=VPB LTC3108.flv&image=video_img.jpg'/></object>";
            animate(elementId, 20, 0, 300, 300, 250, null);

            count = '1';
            newid = "I1";

        }

        if (document.getElementById('HF').value == '1') {
            animate(elementId, 20, 0, 0, 300, 150, null);
            document.getElementById('DV1').innerHTML = "<br/><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='320' height='180' id='Object2' name='single1'> <param name='movie' value='player.swf'/> <param name='allowfullscreen' value='true'/><param name='allowscriptaccess' value='always'/><param name='wmode' value='transparent'/> <param name='flashvars' value='file=vpb 4070 2010jul9.flv&image=video_img.jpg'/><embed src='player.swf' width='270' height='180' allowscriptaccess='always' allowfullscreen='true'flashvars='file=vpb 4070 2010jul9.flv&image=video_img.jpg'/></object>";
            animate(elementId, 20, 0, 300, 300, 150, null);

            count = '2';
            newid = "I2";
        }

        if (document.getElementById('HF').value == '2') {
            animate(elementId, 20, 0, 0, 300, 150, null);
            document.getElementById('DV1').innerHTML = "<br/><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='320' height='180' id='Object2' name='single1'> <param name='movie' value='player.swf'/> <param name='allowfullscreen' value='true'/><param name='allowscriptaccess' value='always'/><param name='wmode' value='transparent'/> <param name='flashvars' value='file=vpb 3109 2010Jun28.flv&image=video_img.jpg'/><embed src='player.swf' width='270' height='180' allowscriptaccess='always' allowfullscreen='true'flashvars='file=vpb 3109 2010Jun28.flv&image=video_img.jpg'/></object>";
            animate(elementId, 20, 0, 300, 300, 150, null);

            count = '3';
            newid = "I3";
        }

        document.getElementById('HF').value = count;
    }

    if (headerId == 'exampleHeader1') {
        if (count == '0') {
            document.getElementById('HF').value = '1';
        }

        if (document.getElementById('HF').value == '1') {
            animate(elementId, 20, 0, 0, 300, 150, null);
            document.getElementById('DV1').innerHTML = "<br/><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='320' height='180' id='Object2' name='single1'> <param name='movie' value='player.swf'/> <param name='allowfullscreen' value='true'/><param name='allowscriptaccess' value='always'/><param name='wmode' value='transparent'/> <param name='flashvars' value='file=vpb 3109 2010Jun28.flv&image=video_img.jpg'/><embed src='player.swf' width='270' height='180' allowscriptaccess='always' allowfullscreen='true'flashvars='file=vpb 3109 2010Jun28.flv&image=video_img.jpg'/></object>";
            animate(elementId, 20, 0, 300, 300, 150, null);

            count = '3';
            newid = "I3";
        }

        if (document.getElementById('HF').value == '3') {
            animate(elementId, 20, 0, 0, 300, 150, null);
            document.getElementById('DV1').innerHTML = "<br/><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='320' height='180' id='Object2' name='single1'> <param name='movie' value='player.swf'/> <param name='allowfullscreen' value='true'/><param name='allowscriptaccess' value='always'/><param name='wmode' value='transparent'/> <param name='flashvars' value='file=vpb 4070 2010jul9.flv&image=video_img.jpg'/><embed src='player.swf' width='270' height='180' allowscriptaccess='always' allowfullscreen='true'flashvars='file=vpb 4070 2010jul9.flv&image=video_img.jpg'/></object>";
            animate(elementId, 20, 0, 300, 300, 150, null);

            count = '2';
            newid = "I2";
        }

        if (document.getElementById('HF').value == '2') {
            animate(elementId, 20, 0, 0, 300, 150, null);
            document.getElementById('DV1').innerHTML = "<br/><object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='320' height='180' id='Object2' name='single1'> <param name='movie' value='player.swf'/> <param name='allowfullscreen' value='true'/><param name='allowscriptaccess' value='always'/><param name='wmode' value='transparent'/> <param name='flashvars' value='file=VPB LTC3108.flv&image=video_img.jpg'/><embed src='player.swf' width='270' height='180' allowscriptaccess='always' allowfullscreen='true'flashvars='file=VPB LTC3108.flv&image=video_img.jpg'/></object>";
            animate(elementId, 20, 0, 300, 300, 150, null);

            count = '0';
            newid = "I1";
        }
        document.getElementById('HF').value = count;
    }
}

function animate(elementID, newLeft, newTop, newWidth,
      newHeight, time, callback) {

    var el = document.getElementById(elementID);
    if (el == null)
        return;

    var cLeft = parseInt(el.style.left);
    var cTop = parseInt(el.style.top);
    var cWidth = parseInt(el.style.width);
    var cHeight = parseInt(el.style.height);

    var totalFrames = 1;
    if (time > 0)
        totalFrames = time / 40;

    var fLeft = newLeft - cLeft;
    if (fLeft != 0)
        fLeft /= totalFrames;

    var fTop = newTop - cTop;
    if (fTop != 0)
        fTop /= totalFrames;

    var fWidth = newWidth - cWidth;
    if (fWidth != 0)
        fWidth /= totalFrames;

    var fHeight = newHeight - cHeight;
    if (fHeight != 0)
        fHeight /= totalFrames;

    doFrame(elementID, cLeft, newLeft, fLeft,
      cTop, newTop, fTop, cWidth, newWidth, fWidth,
      cHeight, newHeight, fHeight, callback);


    //            document.getElementById('DV1').innerHTML = "";
    //            document.getElementById('DV2').style.display = "";
}

function doFrame(eID, cLeft, nLeft, fLeft,
      cTop, nTop, fTop, cWidth, nWidth, fWidth,
      cHeight, nHeight, fHeight, callback) {
    var el = document.getElementById(eID);
    if (el == null)
        return;

    cLeft = moveSingleVal(cLeft, nLeft, fLeft);
    cTop = moveSingleVal(cTop, nTop, fTop);
    cWidth = moveSingleVal(cWidth, nWidth, fWidth);
    cHeight = moveSingleVal(cHeight, nHeight, fHeight);

    el.style.left = Math.round(cLeft) + 'px';
    el.style.top = Math.round(cTop) + 'px';
    el.style.width = Math.round(cWidth) + 'px';
    el.style.height = Math.round(cHeight) + 'px';

    if (cLeft == nLeft && cTop == nTop && cHeight == nHeight
    && cWidth == nWidth) {
        if (callback != null)
            callback();
        return;
    }

    setTimeout('doFrame("' + eID + '",' + cLeft + ',' + nLeft + ',' + fLeft + ','
    + cTop + ',' + nTop + ',' + fTop + ',' + cWidth + ',' + nWidth + ',' + fWidth + ','
    + cHeight + ',' + nHeight + ',' + fHeight + ',' + callback + ')', 40);
}

function moveSingleVal(currentVal, finalVal, frameAmt) {
    if (frameAmt == 0 || currentVal == finalVal)
        return finalVal;

    currentVal += frameAmt;
    if ((frameAmt > 0 && currentVal >= finalVal) || (frameAmt < 0 && currentVal <= finalVal)) {
        return finalVal;
    }
    return currentVal;
}







var TimerID = 0;
var srcevent = "";
var srcindex = "";
var srcid = 0;
var objsrc = 0;
var dataid = "";
var objtrg = 0;
var oEl = null;
var oTarget = null;
var InitPos_X = 0;
var InitPos_Y = 0;
var TargetPos_X = 0;
var TargetPos_Y = 0;
var InitPos_X1 = 0;
var InitPos_Y1 = 0;
var TargetPos_X1 = 0;
var TargetPos_Y1 = 0;
var beginDrag = false;
var tmpHTML = "";
var tag = 0;
var settag = 1;
var Init_Pos = { x: 0, y: 0 };
var Terget_Pos = { x: 0, y: 0 };

function killTimer() {
    if (TimerID != 0) {
        clearTimeout(TimerID);
        TimerID = 0;
    }
}

function fnShowDragWindow() {
    var obj = document.getElementById("DW");

    killTimer();

    if (oEl == null) {
        return;
    }

    obj.style.top = oEl.offsetTop;
    obj.style.left = oEl.offsetLeft;
    obj.style.height = oEl.offsetHeight - 3;
    obj.style.width = oEl.offsetWidth - 3;
    obj.innerText = oEl.SpecimenId;
    obj.style.display = "block";
    obj.style.zIndex = 999;

    if (document.addEventListener) {
        ///////////// For Mozilla //////////////////

        var e = document.getElementById(srcid);

        //        e.addEventListener("mousemove",fnMove,false);                        
        //        e.addEventListener( "scroll"  , fnMove,false);
        //        e.removeEventListener("mousemove",fnMove,true);
        //        e.addEventListener( "mousemove" , fnCheckState,false );
        //        e.addEventListener( "mouseup"    , fnRelease,false );
        //        e.addEventListener( "selectstart", fnSelect,false);        
        //        //e.addEventListener("mouseover",setTarget,false);                  
    }
    else {
        ///////////  For IE  ////////////

        window.document.attachEvent("onmousemove", fnMove);
        window.document.attachEvent("onscroll", fnMove);
        window.document.attachEvent("onmousemove", fnCheckState);
        window.document.attachEvent("onmouseup", fnRelease);
        window.document.attachEvent("onselectstart", fnSelect);
        //window.document.attachEvent("onmouseover",setTarget);
    }

    beginDrag = true;
}

function setTarget(id, e) {
    var src = document.getElementById(id);

    if (src == null) {
        return;
    }

    if (document.addEventListener) {
        if (e.target != null) {
            oTarget = src;
        }
        else {
            oTarget = null;
        }

    }
    else {
        if (src.target == 'true') {
            oTarget = src;
        }
        else {
            oTarget = null;
        }
    }
}

function MayBeBeginDrag(id, e) {
    InitePageX = e.pageX;
    InitePageY = e.pageY;
    DragId = id;
    $(document).bind('mousemove.drag', CheckDrag);
    $(document).bind('mouseup.drag', ClearDragEvents);
}

ClearDragEvents = function () {
    $(document).unbind('mousemove.drag'); 
    $(document).unbind('mouseup.drag');
};

function CheckDrag(e) {
    //alert("BeginDrag");
    //console.log("BeginDrag");
    oEl = document.getElementById(DragId);
    if ((Math.abs(InitePageX - e.pageX) < 25) && (Math.abs(InitePageY - e.pageY) < 25))
        return false;

    ClearDragEvents();
    BeginDrag(DragId, e);
    return false;
}

function BeginDrag(id, e) {
    //alert("BeginDrag");
    //console.log("BeginDrag");
    fun_mousedown('fedvideo_img.jpg');
    oEl = document.getElementById(id);
    InitPos_X = oEl.offsetTop;
    InitPos_Y = oEl.offsetLeft;
    if (newid == "")
        newid = "I1";

    tag = 1;
    settag = 1;

    if (oEl == null) {
        return false;
    }

    tmpHTML = oEl.innerHTML;
    return false;
    //    dataid=dbid;
    //    srcevent=e;    
    //    srcid=id;
    //    srcindex=index;               

    //TimerID = setTimeout(fnShowDragWindow,1);    
}

function StartDrag(id) {
    oEl = document.getElementById(id);

    InitPos_X = oEl.offsetTop;
    InitPos_Y = oEl.offsetLeft;

    if (oEl == null) {
        return;
    }
}

function fnCheckState() {
    if (document.addEventListener) {
        if (srcevent.button != 1) {
            //fnRelease();
        }
    }
    else {
        if (event.button != 1) {
            fnRelease();
        }
    }
    //alert('fnCheckState');
}

function fnSelect() {
    return false;
}


function fnMove() {
    if (window.event) {
        if (event.button != 1) {
            fnRelease();
            return;
        }
    }
    else {
        if (srcevent.button != 1) {
            //fnRelease();                        
            //return;
        }
    }

    var obj = document.getElementById("DW");

    if (document.addEventListener) {
        ///////////// For Mozilla //////////////////

        obj.style.top = srcevent.pageY - (obj.offsetHeight / 2) + document.body.scrollTop;
        obj.style.left = srcevent.pageX + document.body.scrollLeft;
        document.status = 'Top=' + obj.style.top + ' Left=' + obj.style.left;

        if (srcevent.pageY > document.body.clientHeight - 10) {
            window.scrollBy(0, 10);
        }
        else if (srcevent.clientY < 10) {
            window.scrollBy(srcevent.clientX, -10);
        }
    }
    else {
        ///////////// For IE //////////////////

        obj.style.top = event.clientY - (obj.offsetHeight / 2) + window.document.body.scrollTop;
        //alert(obj.style.top); 
        obj.style.left = event.clientX + window.document.body.scrollLeft;
        window.status = 'Top=' + obj.style.top + ' Left=' + obj.style.left;

        if (event.clientY > window.document.body.clientHeight - 10) {
            window.scrollBy(0, 10);
        }
        else if (event.clientY < 10) {
            window.scrollBy(event.clientX, -10);
        }
    } //alert('fnMove');
}

function fnRelease() {
    if (beginDrag == false) return;
    //alert('OK');

    if (document.addEventListener) {
        ///////////// For Mozilla //////////////////

        var e = document.getElementById(srcid);

        e.removeEventListener("mousemove", fnMove, true);
        e.removeEventListener("scroll", fnMove, true);
        e.removeEventListener("mousemove", fnCheckState, true);
        e.removeEventListener("mouseup", fnRelease, true);
        e.removeEventListener("selectstart", fnSelect, true);
        //e.removeEventListener("mouseover",setTarget,true);  

    }
    else {
        ///////////  For IE  ////////////

        window.document.detachEvent("onmousemove", fnMove);
        window.document.detachEvent("onscroll", fnMove);
        window.document.detachEvent("onmousemove", fnCheckState);
        window.document.detachEvent("onmouseup", fnRelease);
        window.document.detachEvent("onselectstart", fnSelect);
        //window.document.detachEvent( "onmouseover", setTarget );

    }


    var obj = document.getElementById("DW");
    if (oTarget != null) {
        if (oTarget.innerHTML != "") {
            oTarget.style.backgroundColor = "beige";
        }
        else {
            oTarget.style.backgroundColor = "turquoise";
        }

        if (oEl.innerHTML != "") {
            oEl.style.backgroundColor = "beige"
        }
        else {
            oEl.style.backgroundColor = "turquoise"
        }
    }

    killTimer();

    obj.style.display = "none";
    oEl = null;
    oTarget = null;
    beginDrag = false;
    TimerID = 0;

}

function CancelDrag() {
    //alert('11111');

    if (tag == 1) {
        //alert(newid);

        if (beginDrag == false) {
            killTimer();
        }

        if (newid != "") {
            WebSrv(newid);
            alert('Favourite Saved');
        }
    }

    tag = 0;
}

function Mouse_Down(index, e) {
    var evtobj = window.event ? event : e;
    Init_Pos = getPosition(evtobj);
}

function Mouse_Over() {

}

function Mouse_Up(index, e) {
    var evtobj = window.event ? event : e;
    Terget_Pos = getPosition(evtobj);

    if (Init_Pos.x > Terget_Pos.x) {
        if (index == '0') {
            location.href = "Home.aspx?Id=4";
        }
        if (index == '1')
            location.href = "Home.aspx?Id=0";
        if (index == '2')
            location.href = "Home.aspx?Id=1";
        if (index == '3')
            location.href = "Home.aspx?Id=2";
        if (index == '4')
            location.href = "Home.aspx?Id=3";
    }
    if (Init_Pos.x < Terget_Pos.x) {
        if (index == '0') {
            location.href = "Home.aspx?Id=1";
        }
        if (index == '1')
            location.href = "Home.aspx?Id=2";
        if (index == '2')
            location.href = "Home.aspx?Id=3";
        if (index == '3')
            location.href = "Home.aspx?Id=4";
        if (index == '4')
            location.href = "Home.aspx?Id=0";
    }
}

function getPosition(e) {
    if (!e)
        e = window.event;
    var cursor = { x: 0, y: 0 };
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    }
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX +
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY +
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

function WebSrv(id) {
    MySampleService.GetServerResponse(id);
}

//  function On_Complete(arg)
//  { 
//     if(arg=="1")
//       alert("This mail has been successfully saved.");
//     else
//       alert("This mail already exsists.");
//  }

function On_Error(arg) {
    alert("The following error has occured : " + arg._message);
}

function On_TimeOut(arg) {
    alert("Time Out Occured.");
}

function FunPos(ev) {
    //oEl = document.getElementById('ctl00_divFav');
    //this.document.getElementById();

    var targ;

    if (settag != 0) {
        if (document.addEventListener) {
            targ = ev.target;
        }
        else {
            var e = window.event;
            targ = e.srcElement;
        }
        var id = targ.id;

        if (id != "ctl00_Contentplaceholder1_ProImage") {

            fun_mouseup(ev);

            if (document.addEventListener) {
                InitPos_X = 3;
                InitPos_Y = 692;
            }
            else {
                InitPos_X = 0;
                InitPos_Y = 441;
            }

            if (document.addEventListener) {
                TargetPos_X = ev.pageX;
                TargetPos_Y = ev.pageY;
            }
            else {
                //var ev = window.event;

                TargetPos_X = window.event.clientX;
                TargetPos_Y = window.event.clientY;
            }
            //alert("X: " + InitPos_X + " Y: " + InitPos_Y);
            //alert("X1: " + TargetPos_X + " Y1: " + TargetPos_Y);

            if ((TargetPos_X >= InitPos_X && TargetPos_X <= (InitPos_X + 300)) && (TargetPos_Y >= InitPos_Y && TargetPos_Y <= (InitPos_Y + 300))) {
                //alert('5');
                tag = 1;
                CancelDrag();
            }
            else {
                tag = 0; // alert("222");
            }
        }
        //alert(InitPos_X);
    }
}

var content = "";
function fun_mousedown(imgname) {
    var trailimage = [imgname, 270, 180];
    var offsetfrommouse = [10, -20];
    var displayduration = 0;

    $(document).bind('mouseup.drag', FunPos);
    $(document).bind('mouseup.drag', ClearDragEvents);

    if (document.getElementById || document.all) {
        if (imgname != "")
            document.getElementById("trailimageid").innerHTML = '<img src="' + trailimage[0] + '" border="0" width="' + trailimage[1] + 'px" height="' + trailimage[2] + 'px">';
        else
            document.getElementById("trailimageid").innerHTML = "";
    }

    function gettrailobj() {
        if (document.getElementById)
            return document.getElementById("trailimageid").style;
        else if (document.all)
            return document.all.trailimagid.style;
    }

    function truebody() {
        return (!window.opera && document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
    }

    function hidetrail() {
        gettrailobj().visibility = "hidden";
        document.onmousemove = "";
    }

    function followmouse(e) {
        //console.log("followmouse");
        var xcoord = offsetfrommouse[0];
        var ycoord = offsetfrommouse[1];
        if (typeof e != "undefined") {
            xcoord += e.pageX;
            ycoord += e.pageY;
        }
        else if (typeof window.event != "undefined") {
            xcoord += truebody().scrollLeft + event.clientX;
            ycoord += truebody().scrollTop + event.clientY;
        }
        var docwidth = document.all ? truebody().scrollLeft + truebody().clientWidth : pageXOffset + window.innerWidth - 15;
        var docheight = document.all ? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight);
        if (xcoord + trailimage[1] + 3 > docwidth || ycoord + trailimage[2] > docheight)
            gettrailobj().display = "none";
        else
            gettrailobj().display = "";
        gettrailobj().left = xcoord + "px";
        gettrailobj().top = ycoord + "px";
        return false;
    }
    //setTimeout("hidetrail()", displayduration * 1000);

    document.onmousemove = followmouse;

    if (displayduration > 0) {
        //setTimeout("hidetrail()", displayduration * 1000);
    }
}

function fun_mouseup(ev) {
    //alert(newid);   

    var TargetPos_X = 0;
    var TargetPos_Y = 0;

    if (document.addEventListener) {
        TargetPos_X = ev.pageX;
        TargetPos_Y = ev.pageY;
    }
    else {
        TargetPos_X = window.event.clientX;
        TargetPos_Y = window.event.clientY;
    }

    if (document.getElementById || document.all) {
        fun_mousedown("");
    }
}

function SetVal() {
    settag = 0;

}

  
