/**
 * @author VERTAZZAR
 * @type JAVASCRIPT (JQUERY 1.4.1 FRAMEWORK)
 * @copyright minisluts.net all rights reserved.
 * 
 * 
 */

$(document).ready(function() {
 

    jQuery('a[rel*=facebox]').facebox();

    
		$('.tooltip-forme').cluetip({ 
 
			width: 300,
			 sticky:           true, 
		 
			 closePosition:    'bottom',
			 dropShadowSteps:  3, 
			  closeText:        'x',
positionBy: 'fixed',
topOffset: '40',
			 cluetipClass: 'black-vert',
			 showTitle: false,
  
			dropShadow: true,
			arrows: true
			
		});	
 		$('.title-tooltip-image').cluetip({ 
			tracking: true,
			cluetipClass: 'black-vert',
			showTitle: false,
			dropShadowSteps:  4, 
			titleAttribute:   'tooltip',
			splitTitle:       '|',
                        width: 'auto',
positionBy: 'mouse',
			dropShadow: true,
			clickThrough: true,
			arrows: true
		});	 
 




 		$('.title-tooltip-static').cluetip({ 
			tracking: true,
			cluetipClass: 'black-vert',
			showTitle: false,
			dropShadowSteps:  4, 
			titleAttribute:   'tooltip',
			splitTitle:       '|',
            width: '375px',
			sticky:           true, 
			closePosition:    'bottom',
			closeText:        'x',
            positionBy: 'fixed',
            topOffset: '40',
			dropShadow: true,
			 mouseOutClose:    true,
			clickThrough: true,
			arrows: true
		});
 		$('.title-tooltip').cluetip({ 
			tracking: true,
			cluetipClass: 'black-vert',
			showTitle: false,
			dropShadowSteps:  4, 
			titleAttribute:   'tooltip',
			splitTitle:       '|',
                        width: '275px',
                        positionBy: 'fixed',
			dropShadow: true,
			clickThrough: true,
			arrows: true
		});
    	$('.vrh').click(function(){
    		$('html, body').animate({scrollTop:0}, 'fast');
    	});

        
    });
 
    

function en(str) {
	
	return encodeURIComponent(str);
	
}

function momalert(){


if ($('#momalerter').html()!='Back') {
	savetitle = $('title').text();
    $('body').attr('save_title', savetitle);
	$('#momalerter').html('Back');
	$('#mompower').show();
	$('#foobar').hide();
	$('title').text('');
	
	} else {
		
		$('#mompower').hide();
		$('#momalerter').html('Mom Alert');
		$('#foobar').show();
		settitle =  $('body').attr('save_title');
		$('title').text(settitle);
		
		} 
		
		}

function ucitavam(tekst) {
 
 if (tekst==undefined) {tekst="Loading...";}
 $('#loader-vertazzar').html(tekst);
	$('#loader-vertazzar').show();
	
}
function gasi_ucitavam(sekunde) {
	if (sekunde==undefined) {sekunde="200";}
    setTimeout(function() {
	$('#loader-vertazzar').hide('slow');
    }, sekunde);
}
function disable_it(sta) {
    $(sta).attr("disabled", "disabled");
}
function gasi_box_sekunde(kolko) {
    setTimeout(function() {
        jQuery(document).trigger('close.facebox');
    }, kolko);
}
function sakri_sekunde(sta, kolko, efekat) {
    setTimeout(function() {
        $(sta).hide(efekat);
    }, kolko);
}
//ajax api box
function ajax_api_box(url) {
	ucitavam();
    jQuery.facebox( {
        ajax: url
    });
    gasi_ucitavam();
    }


function ajax_api_box_img(url) {
	ucitavam();
    jQuery.facebox( {
        image: url
    });
    gasi_ucitavam();
    }
//gasi box
function gasi_box() {
    jQuery(document).trigger('close.facebox');
}

function ajax_get (linka, gdje) {
	
	ucitavam();
    $.ajax( {
        type: "GET",
        url: linka,
        success: function(rezultat) {
        	gasi_ucitavam();
       	    	 
                
        	   $(gdje).html(rezultat);
        	   $(gdje).fadeIn(500);
            }
    });
 
}

function ufav (id) {
	
	ucitavam();
    $.ajax( {
        type: "GET",
        url: '/ajax-korisnik.php?sta=fav&id='+id+'',
        success: function(rezultat) {
        	gasi_ucitavam();
       	    	 alert(rezultat);
                 
            }
    });
 
}

function dfav (id) {
	
	ucitavam();
    $.ajax( {
        type: "GET",
        url: '/ajax-korisnik.php?sta=dfav&id='+id+'',
        success: function(rezultat) {
        	gasi_ucitavam();
       	    	 alert(rezultat);
                 
            }
    });
 
}

function promjenistil (id) {
	
	ucitavam();
    $.ajax( {
        type: "GET",
        url: '/promjenistil.php?id='+id+'',
        success: function(rezultat) {
        	gasi_ucitavam();
       	    	 alert(rezultat.trim());
				 //$('#css').attr('href', '/style'+id+'.css');
				 document.location.href='/';
				 gasi_box_sekunde();
                 
            }
    });
 
}

function komentarisi(sta, id) {

	if (sta=="slika") { 
	sadrzaj = $('#komentar_tekst').val();
	if (sadrzaj=="")  {
		
		 $('#status-forme').html('<div style="font-size:15px;margin-bottom:10px;padding:4px;" class="center ui-state-error fadeaway ui-corner-all">Write down some words!</div>');
		
		ucitavam('<span style="color:red;">Error!</span>');
	
	}
	
	else {
	ucitavam('Commenting...');
	datastring = 'poslano=1&komentar='+en(sadrzaj)+'&id='+id+'';
    $.ajax( {
        type: "POST",
        data: datastring,
        url: '/komentarisi.php?sta='+sta+'&id=' + id,
        success: function(rezultat) {
    	gasi_ucitavam();
   	    	 
    	   $('#ajax_post_komentar').fadeOut(200);
    	   $('#ajax_post_komentar').html(rezultat);
    	   $('#ajax_post_komentar').fadeIn(500);
        }
    });
 
	}
	}
}


function citiraj_komentar_post(sta, id) {
	if (sta=="slika_citiraj") { 
		sadrzaj = $('#cit_komentar_vijest_'+id+'').val();
		if (sadrzaj=="")  {
			
			 $('#status-forme').html('<div style="font-size:15px;padding:4px;margin-bottom:10px;" class="center ui-state-error fadeaway ui-corner-all">Write down some words!</div>');
			
			ucitavam('<span style="color:red;">Error!</span>');
		
		}
		
		else {
		ucitavam('Loading...');
		datastring = 'poslanoc=2&komentar='+en(sadrzaj)+'&id='+id+'';
	    $.ajax( {
	        type: "POST",
	        data: datastring,
	        url: '/komentarisi.php?sta='+sta+'&id=' + id,
	        success: function(rezultat) {
	    	gasi_ucitavam();
	   	    	 
	    	   $('#Citforma_komentar_vijest_'+id+'').fadeOut(200);
	    	   $('#Citforma_komentar_vijest_'+id+'').html(rezultat);
	    	   $('#Citforma_komentar_vijest_'+id+'').fadeIn(500);
	        }
	    });
	 
		}
		}
}

function citiraj_komentar(sta, element, id) {
	ucitavam();
    $.ajax( {
        type: "GET",
        url: '/ajax-forme.php?sta='+sta+'&id=' + id,
        success: function(rezultat) {
        	gasi_ucitavam();
       	    	 
     
        	   $(element).html(rezultat);
        	   $(element).fadeIn(500);
            }
    });
 

	
}

 
function ajax_get_prihvati(id, vrsta) {
	ucitavam();
    $.ajax( {
        type: "GET",
        url: '/ajax-admin.php?vrsta=slika&sta='+vrsta+'&id=' + id,
        success: function(rezultat) {
        	gasi_ucitavam();
       	    	 
     
        	   $('#poruke-'+id+'').html(rezultat);
       
            }
    });
 
}


function brisi_komentar(sta) {
    if (confirm('Are you sure?')) {
    	ucitavam('Delete in process...');
        $.ajax( {
            type: "GET",
            url: '/ajax-admin.php?vrsta=brisi_komentar&id=' + sta + '',
            success: function(rezultat) {
        	gasi_ucitavam();
     
                 $('#komentarbr-' + sta + '').hide('slow');
                
                
            }
        });
        return false;
    } else {
        return false;
    }
}

function recX (id) { 
    ucitavam('Delete in process...');
        $.ajax( {
            type: "GET",
            url: '/ajax-korisnik.php?sta=rele&id=' + id + '',
            success: function(rezultat) {
        	gasi_ucitavam();
     
                 $('#Re_' + id + '').remove();
                 $('#recommandit').append(rezultat);
                
                
            }
        });

}



function Follow (id, action) { 
    ucitavam();
        $.ajax( {
            type: "GET",
            url: '/ajax-friends.php?sta=friend&id=' + id +  '&command=' + action + '',
            success: function(rezultat) {
        	gasi_ucitavam();
                $(this).remove();
                
                
            }
        });

}

function getMoarC ( o ) {
    ucitavam();
        $.ajax( {
            type: "GET",
            url: '/commentz.php?moar=true&oh=' + o + '',
            success: function(rezultat) {
        	gasi_ucitavam();
     
              
                 $('#ajaxer-comments').append(rezultat);
                
                
            }
        });
}

function submitTerms(id) {
 var terms = en($('#saver').val());
    ucitavam();
        $.ajax( {
            type: "GET",
            url: '/commentz.php?id=' + id + '&tags=' + terms + '',
            success: function(rezultat) {
        	gasi_ucitavam();
      if (rezultat.trim()!='OK') { $('#showav').html('<div style="font-size:15px;padding:4px;margin-bottom:10px;" class="center ui-state-error fadeaway ui-corner-all">Something went wrong, please try again by clicking <a href="javascript:;" onclick="window.location.reload(true);">here</a>.</div>'); } else {
              
                 $('#showav').html('<div style="font-size:15px;padding:4px;margin-bottom:10px;" class="center ui-state-highlight fadeaway ui-corner-all">The tags are sent to administration for review! Thank you</div>');
$('#selected_What').remove(); }
                
                
            }
        });
}


function PM_Handler (action, id, type) {
	if (action=="brisi_pm") {
	 
			$('#poruke-'+id+'').remove();
			ajax_get('/ajax-poruke.php?vrsta='+type+'&sta=brisi_pm&id='+id+'');
			return true;
 
		
	}
	var tekst = en($('#PM_Value_'+id+'').val());
	$('#PM_Value_'+id+' textarea').attr('disabled','disabled');
    $.ajax( {
        type: "POST",
        data: 'tekst='+tekst+'',
        url:  '/ajax-poruke.php?vrsta='+type+'&sta='+action+'&id='+id+'',
        success: function(result) {
    	gasi_ucitavam();
		$('#tothebatmobile').append(result);
    	if (action=="nova_kome") {
    		gasi_box_sekunde(2000);
    	}
    	$('#PM_Value_'+id+' textarea').removeAttr('disabled');
    	$('#PM_Value_'+id+'').val('');
      
        }
    });
    
    
}


function Set_Append_Value (eleid, str, separator) {
	
    val = $(eleid).val();
	if (val!='') {
		
		$(eleid).val(val+''+separator+''+str+'');
	} else {
		$(eleid).val(str);
	}
}
function bookmarksite(a,b){if(window.sidebar)window.sidebar.addPanel(a,b,"");else if(window.opera&&window.print){var c=document.createElement("a");c.setAttribute("href",b);c.setAttribute("title",a);c.setAttribute("rel","sidebar");c.click()}else document.all?window.external.AddFavorite(b,a):alert("Press < Ctrl > + D to bookmark in Chrome")
}
