$(document).ready(function(){
	/* INITIALIZING PRELOADER */
	$.preload(urls,{
		base:Drupal.settings.basePath + 'sites/all/themes/tn34/images/',
		//base:'./images/',
		onRequest:function(){
			$('div.image-frame').addClass('loading');
		},
		onFinish:function(data){
			var img = new Image();
			img.src = data.image;
			$('div.image-frame').removeClass('loading');
			$('div.image-frame').prepend(img);
			if(itisIE6 == true){				
				$('.image-frame').pngFix({},'crop');
			}
		}
	});
					   
	/* STYLING SELECT BOXES */	
	$('select.dropdown-cat').sSelect().change(function(){
		$('form#sorting').submit();
	});
	$('select.dropdown-date').sSelect().change(function() {
		$('form#sorting').submit();
	});
		
	/* HIDE SUBMIT BTN ON PORTFOLIO */
	$('#sort-go').hide();
	
	/* HOVER EFFECT SHOWREEL */
	$('div.showreel .panel').hover(function(){
		$(this).children('div.info').animate({top:0},{queue:false, duration:500});
	},function(){
		$(this).children('div.info').animate({top:200},{queue:false, duration:500});
	});	
	
	/* HOVER EFFECT PORTFOLIO ITEM */
	$('ul#portfolio-list li .panel').hover(function(){
		$(this).children('div.info').animate({top:0},{queue:false, duration:500});
	},function(){
		$(this).children('div.info').animate({top:110},{queue:false, duration:500});
	});	
	
	/* MAKE div.info clickable */
	$('div.info').css('cursor','pointer').click(function(){
		var NewLink= $(this).children('a.action-link').attr("href");
		window.location.href = NewLink;
	});
	
	/* TODO PORTFOLIOP LIST one() */
	
	/* PORTFOLIO SLIDER */
	if($('div#slider ul li').length > 1){
		$("div#slider").easySlider({
			auto: false,
			continuous: true,
			numeric: true,
			prevId: 		'prevImg',
			nextId: 		'nextImg'
		});
	}

	$('span#prevImg, span#nextImg').hover(function(){
		$(this).children("a").fadeIn('fast');
	}, function(){
		$(this).children("a").fadeOut('fast');
	});
	 
	 /* KONTAKT MAGNIFIER */
	$('a#lupe').show().loupe({
		width:300,
		height:200
	});
	
	/* DTD TARGET BLANK LINKS FIX */
	$('a[rel="external"], ul.flickr-gallery li a').attr('target','_blank');
	
  $('#leistungen').parent('a').attr('href', Drupal.settings.basePath + 'leistungen-als-internetagentur.html');
	$('ul#submenu-2189 li').each(function(index) {
		//console.log('leistungen-als-internetagentur.html?tab='+index);
		
		$(this).children('a').attr('href', Drupal.settings.basePath + 'leistungen-als-internetagentur.html?tab='+index)
	});
});
/* CUFON - FONT REPLACEMENT */
Cufon.replace('h1.category', { fontFamily: 'DIN Regular' });
Cufon.replace('div.category', { fontFamily: 'DIN Regular' });
Cufon.replace('div.category span', { fontFamily: 'DIN Light' });
Cufon.replace('ul#navigation li a span', { fontFamily: 'DIN Light' });

$('h1').each(function(index, value) {
	//alert(value.innerHTML + " CN: '" +value.className + "'");
	if(value.className ==  '' ) {
		//alert('h1' + h1.className);
		Cufon.replace(value, { fontFamily: 'DIN Light' });		
	}
});

$('h2').each(function(index, value) {
	//alert(value.innerHTML + " CN: '" +value.className + "'");
	if(value.className ==  '' ) {
		//alert('h1' + h1.className);
		Cufon.replace(value, { fontFamily: 'DIN Light' });		
	}
});

/* FOOTER FONT REPLACEMENT */
Cufon.replace('#footlinks a', { fontFamily: 'DIN Regular' });

/*
Cufon.replace('h1', { fontFamily: 'DIN Light' });
*/

Cufon.replace('#post #text, #post form fieldset.replace', { fontFamily: 'vinchand' });
Cufon.replace('#post h1, div.replace p', { fontFamily: 'vinchand' });
Cufon.now();