$(document).ready( function(){
	changeNSState();
	Cufon.replace('.hp-sub .title,.smart-shopping .title,.discount,.special-offers .title,.special-offers .price,h1,h2,h3', {
		fontFamily:'Trebuchet MS',
		fontWeight:'normal'
	});

	Cufon.replace('a.li-title,.shp-new-price span,.shp-sub span', {
		fontFamily:'Trebuchet MS',
		fontWeight:'bold'
	});	
	
	$(document).ready(function(){
		$('#mycarousel').jcarousel();
	});
	
	$("a.fancybox").fancybox();
	
	$('#nwl-head').click(function()
	{
		$(this).toggleClass('nwl-head-active');
		$('#nwl-body').toggle();
	});
	
	$('#nwl-email').click(function()
	{
		$(this).val('');
	});
	
	$('#nwl-email').blur(function()
	{
		$(this).val('Adresa de email...');
	});
	
	
    
    $('#nwl-submit').bind('click', function()
    {
        $.ajax(
        {
            type:'POST',
            url:'http://www.fashionhouse.ro/newsletter_new.php',
            data:'name=' + $('#nwl-inp1').val() + '&email=' +  $('#nwl-inp2').val() + '&phone=' + $('#nwl-inp3').val() + '&sex=' + $('#nwl-sex input:radio:checked').val(),
            success: function(msg)
            {
                if (msg == 'ok')
                {
                    //alert('e ok');
                    $('#nwl-result').html('');
                    $('#nwl-result').html('Te-ai abonat, felicitari !');
                }
                else
                {
                    if (msg == 'ok')
                    {        
                        $('#nwl-result').html('');
                        $('#nwl-result').html('Te-ai abonat, Felicitari !');
                    }
                    else
                    {
                        $('#nwl-result').html(msg);
                    }
                }
            }
        });
    });
   
		
    postResponse( );
    
    /* chestionar */ 
    $("#a-chestionar").fancybox({
//        frameWidth: 'auto',
//        frameHeight: 300,  
//		width: 530,
//		height: 'auto',
        hideOnContentClick: false,
        autoScale: true,
        autoDimensions: true,
        showCloseButton : true,
        hideOnOverlayClick: false                
    });
	    
});

function changeNSState()
{
	if($('#newsletter.bk_newsletter'))
	{
		$('#nwl-inp1').click(function(){
				/*if(jQuery.trim(this.value) == '')
				{
					
				}*/
				$(this).removeClass('elemEmpty');
			}
		)
		
		$('#nwl-inp2').click(function(){
				$(this).removeClass('elemEmpty');
			}
		)
		$('#nwl-inp3').click(function(){
				$(this).removeClass('elemEmpty');
			}
		)
		
		$('#nwl-inp1').blur(function(){
				if(jQuery.trim(this.value) == '')
				{
					$(this).addClass('elemEmpty');
				}
			}
		)
		$('#nwl-inp2').blur(function(){
				if(jQuery.trim(this.value) == '')
				{
					$(this).addClass('elemEmpty');
				}
			}
		)
		$('#nwl-inp3').blur(function(){
				if(jQuery.trim(this.value) == '')
				{
					$(this).addClass('elemEmpty');
				}
			}
		)
		
	}
}

function postResponse( qId, rId )
{
	if(!qId){qId=0}
	if(!rId){rId=0}
    $.post(
    		"http://www.fashionhouse.ro/chestionar_new.php", 
    		{qId:qId,rId:rId},
			function(data) {
				$('.img-intrebare').attr('src','/wp-content/themes/sandbox/!res/img/chestionar/'+ data['q_pic']);
//	                $('.img-intrebare').attr('style','padding-top:50px;');

				$('.p-raspunsuri').html('');
				var raspunsContent = '';
				
				for(var i in data.answers) {
					var value = data.answers[i];
					raspunsContent += '<p><a class="a-left" href="#" onclick="javascript:postResponse(\''+data['id']+'\',\''+value['id']+'\');"></a><span class="sp-right">'+value['answer']+'</span></p>';
				}
				
				if( data['xtra_content'] )
				{
					raspunsContent += '<p class="fancyXtra">'+data['xtra_content']+'</p>';
				}
				
				
				raspunsContent += '<p><span class="sp-right">&nbsp;</span></p>';
                $('.p-raspunsuri').html(raspunsContent);
                
                $.fancybox.resize;
                $.fancybox.center;
			},
			'json'
		);
}

/* chestionar */ 
function send_ajax(val){
    if($('.img-intrebare').attr('src')=='/wp-content/themes/sandbox/!res/img/chestionar/raspuns-ok.png')
    {
        $('.p-raspunsuri').attr('style','display:none');
        $('.img-intrebare').attr('style','padding-top:50px;');
        exit();
    }
    $('div#fancy_div a.a-left').attr('style','background:url("/wp-content/themes/sandbox/!res/img/chestionar/casuta-goala.png") no-repeat top right');
    if(val==1)
        $('div#fancy_div a.a-da').attr('style','background:url("/wp-content/themes/sandbox/!res/img/chestionar/casuta-plina.png") no-repeat top right');
    if(val==2)
        $('div#fancy_div a.a-nu').attr('style','background:url("/wp-content/themes/sandbox/!res/img/chestionar/casuta-plina.png") no-repeat top right');
        
    $.ajax(
    {
        type:'POST',
        url:'http://www.fashionhouse.ro/chestionar.php',
        data:'val=' + val,
        success: function(msg)
        {
            $('.p-raspunsuri').attr('style','display:none');
            if(msg=='ok')
            {
                $('.img-intrebare').attr('src','/wp-content/themes/sandbox/!res/img/chestionar/raspuns-ok.png');
                $('.img-intrebare').attr('style','padding-top:50px;');
            } 
                
            else
            {
                $('.img-intrebare').attr('src','/wp-content/themes/sandbox/!res/img/chestionar/raspuns-not-ok.png');
                $('.img-intrebare').attr('style','padding-top:50px;');
            }
                
            
            /*$('div#fancy_div .d-result').html('<p>'+msg+'</p>');*/
            
            /* close it */
            /*sleep(5000);
            $('#fancy_close').click();            
            */
            
            /*
            $('#fancy_div div#p-raspunsuri').fadeOut('slow');
            
            $('#fancy_div div#d-result').fadeIn('slow');
            */
            
            /*
            if (msg == 'ok')
            {
                $('#d-result').html(msg);
            }
            else
            {
                $('#d-result').html(msg);
            }
            */
        }
    });
}
function sleep(milliseconds) {
  var start = new Date().getTime();
  for (var i = 0; i < 1e7; i++) {
    if ((new Date().getTime() - start) > milliseconds){
      break;
    }
  }
}

