/************************************************************************************************************
*	DHTML modal dialog box
*
*	Created:						May, 3rd, 2011
*	@class Purpose of class:				Load modal-message.js after certain delay
*			
*	Css files used by this script:	N/A
*
*	Demos of this class:			ctime.html
*
*	Start Function: 			start(minute,second)
************************************************************************************************************/
/**
* @nishith
*/

function preloadImage(imagePath)
{
        var img = document.createElement('IMG');
        img.src = imagePath;            
}




function start(mi,sec){
	startCountDown((mi*60+sec), 1000, showDHTML);
	//preloadImage('imagePreload' + document.getElementById("imgnow").innerHTML);
}

function startCountDown(i, p, f) {
    // store parameters
    var pause = p;
    var fn = f;
    // make reference to div
    var countDownObj = document.getElementById("countDown");
    if (countDownObj == null) {
        // error
        alert("div not found, check your id");
        // bail
        return;
    }
    countDownObj.count = function(i) {
    // write out count
    countDownObj.innerHTML = Math.floor(i/60)+"min "+i%60+"sec";
    //countDownObj.innerHTML = i+i;

    if (i == 0) {
        // execute function
        fn();
        // stop
        return;
    }
    setTimeout(function() {
            // repeat
            countDownObj.count(i - 1);
        },pause);
    }
    // set it going
    countDownObj.count(i);
}


function loadScript() {
    var NewScript=document.createElement('script');
    NewScript.src="modal-message.js" ;
    document.body.appendChild(NewScript);
    setTimeout("showDHTML()",1000);
}

function showDHTML(){


	var number = document.getElementById("imgnow").innerHTML;
	var fadeoutnumber = document.getElementById("imgfade").innerHTML;
	var numberamount = document.getElementById("imgamount").innerHTML;
	if(fadeoutnumber != ''){
    jQuery("#picturediv" + fadeoutnumber).fadeOut(1000);
	}
    jQuery("#picturediv" + number).fadeIn(1000);
	document.getElementById("imgfade").innerHTML = number;
//	$("picturediv" + number).fadeIn(100);
	number++;
	document.getElementById("imgnow").innerHTML = number;
	if(number <= numberamount){
	start(0,20);
	}else{
		number=1;
		document.getElementById("imgnow").innerHTML = number;start(0,20);
	}

}

