/*Cufon.replace('.menu>ul>li>a');*/
var arr = ["'one'","'two'","'three'"];
var arr_t = ["one","two","three"];
var ind = 0;
var ind_item = 1;
$(document).ready(function(){
	$('.rotator').cycle({
		timeout: 5000
	});
	
	$('.sub-menu').each(function(){
		var str_html = $(this).parent().html();
		var html_link = $(this).parent().parent().children('A').html();
		var href_link = $(this).parent().parent().children('A').attr('href');
		
        $(this).parent('div').replaceWith('<div id="'+arr_t[ind]+'-ddcontent" onmouseout="ddMenu('+arr[ind]+',-1)" onmouseover="cancelHide('+arr[ind]+')">'+str_html+'</div>'); 
		$('#'+arr_t[ind]+'-ddcontent').parent('li').children('A').replaceWith('<a href="'+href_link+'" id="'+arr_t[ind]+'-ddheader" onmouseout="ddMenu('+arr[ind]+',-1)" onmouseover="ddMenu('+arr[ind]+',1)">'+html_link+'</a>');
		ind = ind + 1; 
		
    });
	Cufon.replace('.menu>ul>li>a'); 
	
	
	$('.form-box .comment-form-comment TEXTAREA').wrap('<div class="textarea"></div>');
	var com_html = $('.form-box .comment-form-comment').html();
	$('.form-box .comment-form-comment').replaceWith('<div class="row">'+com_html+'</div>');
	
	if ($('.wpcf7-form').length > 0) {
		$('div.wpcf7-response-output').replaceWith('');
		$('.wpcf7').prepend('<div class="wpcf7-response-output wpcf7-display-none"></div>');
	};
	
	$('#gallery-1 .gallery-item').each(function(){
		var ost = ind_item % 5;
		if (ost == 0) {
			$(this).addClass('last');
			ind_item = 1;
		}
		ind_item = ind_item + 1;
			
	});
	
})
	




var DDSPEED = 3;
var DDTIMER = 5;

// main function to handle the mouse events //
function ddMenu(id,d){
    var h = document.getElementById(id + '-ddheader');
    var c = document.getElementById(id + '-ddcontent');
    clearInterval(c.timer);
    if(d == 1){
        clearTimeout(h.timer);
        if(c.maxh && c.maxh <= c.offsetHeight){return}
    else {
        c.style.display = 'block';
        c.style.height = 'auto';
        c.maxh = c.offsetHeight;
        c.style.height = '1px';
    }
        c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
    }else{
        h.timer = setTimeout(function(){ddCollapse(c)},30);
    }
}

// collapse the menu //
function ddCollapse(c){
    c.timer = setInterval(function(){ddSlide(c,-1)},DDTIMER);
}

// cancel the collapse if a user rolls over the dropdown //
function cancelHide(id){
    var h = document.getElementById(id + '-ddheader');
    var c = document.getElementById(id + '-ddcontent');
    clearTimeout(h.timer);
    clearInterval(c.timer);
    if(c.offsetHeight < c.maxh){
        c.timer = setInterval(function(){ddSlide(c,1)},DDTIMER);
    }
}

// incrementally expand/contract the dropdown and change the opacity //
function ddSlide(c,d){
    var currh = c.offsetHeight;
    var dist;
    if(d == 1){
        dist = (Math.round((c.maxh - currh) / DDSPEED));
    }else{
        dist = (Math.round(currh / DDSPEED));
    }
    if(dist <= 1 && d == 1){
        dist = 1;
    }
    c.style.height = currh + (dist * d) + 'px';
    c.style.opacity = currh / c.maxh;
    c.style.filter = 'alpha(opacity=' + (currh * 100 / c.maxh) + ')';
    if((currh < 2 && d != 1) || (currh > (c.maxh - 2) && d == 1)){
        clearInterval(c.timer);
       
    }
}
