$(document).ready(function() {
	$("#get_flash").show();
	create_offer();

	$("#test").pngfix();
	$("#abs div").pngfix();
	$("img[src=png], .object_pic").pngfix();
});


function change_toggle_section()
{    
     if ($('#searchBox > ul').data('selected.tabs')==0) {$("#section-3-auto").show();} else {$("#section-3-auto").hide();}
     if ($('#searchBox > ul').data('selected.tabs')==1) {$("#section-3-moto").toggle();} else {$("#section-3-moto").hide();}
     if ($('#searchBox > ul').data('selected.tabs')==2) {$("#section-3-water").toggle();} else {$("#section-3-water").hide();}
     if ($('#searchBox > ul').data('selected.tabs')==3) {$("#section-3-qvad").toggle();} else {$("#section-3-qvad").hide();} 
}



function create_offer ()
{
	if (offers.length > 0)
	{
		var rand_no = Math.floor(((offers.length+4)-4)*Math.random()) + 0;
		
		// Ja vajag konkretu tad nosetojam konkretu kartas Nr
		// Lidz 09.03.2009
		//rand_no = 3;
		// ##########################################
        
		var i = 0;
        var content = "";
        
    	jQuery.each(offers, function() {
			content += '<div class="offer" id="div'+i+'"><a href="javascript:chage_offer('+i+');">'+(i+1)+'</a></div>';
   			i++;
    	});

		$("#offers").html(content);

        $("#div"+rand_no).removeClass("offer");
        $("#div"+rand_no).addClass("offer_active");
        
        $("#offer-title").html(offers[rand_no]['name']);
        
        if (offers[rand_no]['type']=="img")
        {
        	$("#offer-img").html('<a href="'+offers[rand_no]['url']+'" target="'+offers[rand_no]['tar']+'"><img src="/img/banners/'+offers[rand_no]['src']+'" alt="'+offers[rand_no]['name']+'" title="'+offers[rand_no]['name']+'" width="540" height="230" border="0" /></a>');
		}
        else if (offers[rand_no]['type']=="swf")
		{
			swfobject.embedSWF("/img/flash.swf?m=/img/banners/"+offers[rand_no]['src']+"&l="+offers[rand_no]['url']+"&t="+offers[rand_no]['tar']+"&w=540&h=230", "offer-swf", "540", "230", "9.0.0", "/img/banners/expressInstall.swf","false",{wmode:"transparent"});
		}
	}
}



function chage_offer(offer)
{
	$("#offers div").removeClass("offer");
	$("#offers div").removeClass("offer_active");
	$("#offers div").addClass("offer");
	$("#div"+offer).removeClass("offer"); 
	$("#div"+offer).addClass("offer_active");
	$("#offer-title").html(offers[offer]['name']);
	$("#offer-img").html("");
	
	if (offers[offer]['type']=="img")
	{
		$("#offer-img").html('<a href="'+offers[offer]['url']+'" target="'+offers[offer]['tar']+'"><img src="/img/banners/'+offers[offer]['src']+'" alt="'+offers[offer]['name']+'" title="'+offers[offer]['name']+'" width="540" height="230" border="0" /></a>');
	}
	else if (offers[offer]['type']=="swf")
	{ 					
		$("#offer-img").html("");    
		$("#offer-img").html('<div id="offer-swf"><p id="get_flash" style="padding-top:30px; display:none;"><a href="http://www.adobe.com/go/getflashplayer"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" border="0" /></a></p></div>');
		swfobject.embedSWF("/img/flash.swf?m=/img/banners/"+offers[offer]['src']+"&l="+offers[offer]['url']+"&t="+offers[offer]['tar']+"&w=540&h=230", "offer-swf", "540", "230", "9.0.0", "/img/banners/expressInstall.swf","false",{wmode:"transparent"});
	}    
}
