﻿$(document).ready(function(){

var debug = 0;
if (debug) {$("#alpha").prepend('<div class="box1 message"><p>Testresultat:</p></div>');}

    /* BOXAR */
    $("div.box1").prepend('<img class="box1-img-top" src="assets/templates/ssn01/images/sidebar-top.jpg" />');
    $("div.box1").append('<img class="box1-img-bottom" src="assets/templates/ssn01/images/sidebar-bottom.jpg" />');
    
    
    /* WLPE form */
    $("#wlpe input").focus(function(){
        $("div.box1 p.response").hide(200);
        $(this).next("p.info").addClass('response').fadeIn("normal");
		$(this).parent().parent().find("img.box1-img-bottom").hide().show(220); // Make sure IE7 rerender the box;
    });
    
    $("#wlpe input").blur(function(){
        $(this).next("p").hide(200);
    });


	// Load ajax image for sms-ads
	$("#beta div.box1.cat-and-sms").eq(0).find("p").after('<img style="display:block;padding:10px 0 20px 43px;" class="loading" src="/assets/templates/ssn01/images/ajax-loader.gif" />');

	
		// Ladda html: sms-ads EFTER en tid satt av timer
		startLoadAds = function() {

			 $.get("/data/smsad.xml", function(data){
			
				$(data).find("kategori").each(function(){
					var $entry = $(this);
					var $kategori = $entry.attr('kat');	
					var findCatInP = 'div.box1.cat-and-sms p:contains("' + $kategori + '")';
					
						if (($kategori == 'Klicka') || ($kategori == 'Shemales') || ($kategori == 'Gamlingar')) {
		
							if ($kategori == 'Klicka') {
								$(findCatInP).after($entry.text());
							} else {
								$(findCatInP).after('<div class="smsad smsad-kategori">' + $entry.text() + '</div>');
							}	
						}
						else {
								$(findCatInP).next('div.titlar').after('<div class="smsad smsad-kategori">' + $entry.text() + '</div>');
						}	
				});
				
						// After xml file loaded this function is called from timer
						var x=0;
						var z; //Don't set to 0, will show first one
						timadVisning = function(){
									$("img.loading").hide();
									$("#beta div.box1.cat-and-sms .smsad").eq(x).show()
									.parent().find("img.box1-img-bottom").hide().show(); // Make sure IE7 rerender the box
									if (x<2) $("img.loading").show();
							if ((x>2) && (x<7)) {
								if (x==3) {z=0;}
									$("#alpha div.box1.cat-and-sms .smsad").eq(z).show()
									.parent().find("img.box1-img-bottom").hide().show(); // Make sure IE7 rerender the box;
								z++;
							}
							x++;
						};	// End Function timadVisning		
		
		
				// Start showning sms ads after xml file injected
				for (var i=1; i<14; i++) {
					var y=1;
					if (i==2) {y=1;}
					if (i==3) {y=1;}
					if (i>3) {y=300;}
					timeoutID = window.setTimeout('timadVisning()', (i*y));
				};
	
			}); // End $.get()
			
		}; // End function startLoadingAds
		
		/* LOW Priority: wait 1500ms and start load ads: */		
		timeoutID = window.setTimeout('startLoadAds()', 500);

}); // End document.ready






//timeoutID = window.setTimeout('$("div.smsad-kategori.Lesbiskt").load("/data/smsad/Lesbiskt.html").show();', 10000);
//timeoutID = window.setTimeout('$("div.box1.cat-and-sms .smsad").show()', 5000);	
//intervalID = window.setInterval(code, delay);
/*

   setTimeout( function() {
      alert( 'timer!' );
   }, 1000 ); 
  

http://groups.google.com/group/jquery-en/browse_thread/thread/487abbad7bafcf3a/3ceb689961e13fe5?lnk=gst&q=settimeout#3ceb689961e13fe5
http://jquery.offput.ca/timers/
*/

//if (debug) {$("#alpha div:first").prepend('<p>' + timeoutID + ' X: ' + x + '</p>');}

/*
window.onload = function(){ 
var datumOnLoad = new Date();	
var tidOnLoad = datumOnLoad.getTime();
$("#alpha").prepend('<div class="box1 message"><p>onLoad! ' + tidOnLoad + ' </p></div>');
};
*/
