﻿var theImages = new Array()
var theTexts = new Array()

theImages[0] = 'images/bg-cmuk.jpg'
theTexts[0] = 'CMUK, Gitanes Bar, 1993'
theImages[1] = 'images/bg-cmuktayfa.jpg'
theTexts[1] = 'CMUK Crew, İstanbul, 1993'
theImages[2] = 'images/bg-headbangers-2.jpg'
theTexts[2] = 'Headbangers (Collage by Sercan Headbangers)'
theImages[3] = 'images/bg-headbangers.jpg'
theTexts[3] = 'Headbangers, Merhaba Disco, 1989'
theImages[4] = 'images/bg-hkv.jpg'
theTexts[4] = 'Hong Kong Virus, 1997'
theImages[5] = 'images/bg-kelmemedoff.jpg'
theTexts[5] = '"Kel Memedoff"'
theImages[6] = 'images/bg-mandala.jpg'
theTexts[6] = 'Mandala Bar, 1994'
theImages[7] = 'images/bg-mondotrasho.jpg'
theTexts[7] = 'Esat Başak, 1995'
theImages[8] = 'images/bg-moribundyouth.jpg'
theTexts[8] = 'Moribund Youth, Bilsak 1991'
theImages[9] = 'images/bg-noisymob.jpg'
theTexts[9] = 'Noisy Mob, Bilsak 1991'
theImages[10] = 'images/bg-radicalnoise.jpg'
theTexts[10] = 'Radical Noise, Gitanes Bar 1994'
theImages[11] = 'images/bg-rashit.jpg'
theTexts[11] = 'Rashit Poster, 1995'
theImages[12] = 'images/bg-sevdasizhayat.jpg'
theTexts[12] = '"Sevdasız Hayat Ölümdür", 1994'
theImages[13] = 'images/bg-spinners.jpg'
theTexts[13] = 'Spinners, Grafitti Bar 1990'
theImages[14] = 'images/bg-tampon.jpg'
theTexts[14] = 'Tampon, 1995'
theImages[15] = 'images/bg-timur.jpg'
theTexts[15] = 'Timur CMUK, 1996'
theImages[16] = 'images/bg-kemalaydemir.jpg'
theTexts[16] = 'Kemal Aydemir'
theImages[17] = 'images/bg-tunayakdeniz.jpg'
theTexts[17] = 'Tünay Akdeniz, 1978'

var j = 0;
var p = theImages.length;

var cookieR = readCookie('trkpnkcookie');
if ( cookieR ) {
       j=parseInt(cookieR);
}
else{
       var whichImage = Math.round(Math.random()*(p-1));
       j=whichImage;
}


var preBuffer = new Array()
var preTextor = new Array()
for (i = 0; i < p; i++){
 preBuffer[i] = new Image()
 preBuffer[i].src = theImages[i]
 preTextor[i] = new Image()
 preTextor[i].src = theTexts[i]
}

//function showImage(){
//document.write('<img src="'+theImages[j]+'">');
//}
function showImage(){
document.write("<img id='bgimg' src='"+theImages[j]+"'>");
}
function showText(){
document.write(theTexts[j]);
}
function showImage2(){
       var cookieR2 = readCookie('trkpnkcookie');
       if ( cookieR2 ) {
               randomImg();
       }
	        j++;
   		if( j >= p ){
  		       j = 0;
   		}
   		document.getElementById("bgimg").src = theImages[j];
   		document.getElementById("credit-txt").innerHTML = theTexts[j];

}


function createCookie(name,value,days) {
       if (days) {
               var date = new Date();
               date.setTime(date.getTime()+(days*24*60*60*1000));
               var expires = "; expires="+date.toGMTString();
       }
       else var expires = "";
       document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
       var nameEQ = name + "=";
       var ca = document.cookie.split(';');
       for(var i=0;i < ca.length;i++) {
               var c = ca[i];
               while (c.charAt(0)==' ') c = c.substring(1,c.length);
               if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
       }
       return null;
}

function eraseCookie(name) {
       createCookie(name,"",-1);
}

function setDefaultImg(){
       var sr = document.getElementById('random-content');
       var cookieR2 = readCookie('trkpnkcookie');
       if ( cookieR2 ) {
               eraseCookie('trkpnkcookie');
       }
		str = document.getElementById("bgimg").src; 
               index = 0;
               for( i=0; i<theImages.length; i++ )
               {
                       if( theImages[i].substring(theImages[i].lastIndexOf('/')) == str.substring(str.lastIndexOf('/') )){
                               index = i;
                       }
               }
               createCookie('trkpnkcookie',index,365);
	       sr.innerHTML = "<a href='javascript:randomImg();'>Random background image</a>";

}

function randomImg(){
       var sr = document.getElementById('random-content');
       var cookieR2 = readCookie('trkpnkcookie');
       if ( cookieR2 ) {
               eraseCookie('trkpnkcookie');
	       sr.innerHTML = "<a href='javascript:setDefaultImg();'>Set as default</a>";
       }else{
	       sr.innerHTML = "<a href='javascript:randomImg();'>Random background image</a>";
       }
}

function setRandomLink(){
	var cookieR3 = readCookie('trkpnkcookie');
       if ( cookieR3 ) {
	       document.write("<a href='javascript:randomImg();'>Random background image</a>");	
       }else{
	       document.write("<a href='javascript:setDefaultImg();'>Set as default</a>");
       }
}


